logging

package
v0.0.0-...-eeffcdd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogChainer

type LogChainer interface {
	ElapsedTime(dur time.Duration) LogChainer
	CodeID(c string) LogChainer
	Signal(s string) LogChainer

	// These are the last functions that should be called on a log chain.
	// These will execute and log all the information
	Panic(msg string)
	Fatal(msg string, err error)
	Error(msg string, err error)
	Warn(msg string)
	Info(msg string)
	Debug(msg string)
}

LogChainer defines the behavior of the logger. Exposes a function for each loggable field which maps to a LogKey. The functions invocations can be chained and terminated by one of the levelled function calls (Fatal, Error, Warn, Info).

type LogKey

type LogKey string

LogKey is the type each key that appears in the log should be.

const (
	CallerKey      LogKey = "caller"
	CodeKey        LogKey = "code_id"
	ElapsedTimeKey LogKey = "elapsed_time"
	ServiceKey     LogKey = "service"
	SignalKey      LogKey = "signal"
)

Each LogKey appearing in the logs is defined in the following const block.

func (LogKey) String

func (lk LogKey) String() string

String returns the string representation of the LogKey

type LogLevel

type LogLevel int

LogLevel represents the logging level.

const (
	DEBUG LogLevel = iota
	INFO
	WARNING
	ERROR
	FATAL
	PANIC
	DISABLED
)

type Logger

type Logger struct {
	Zero zerolog.Logger
}

Logger implements the LogChainer interface and relies on http://github.com/rs/zerolog

func GetLogger

func GetLogger(service string, logLevel LogLevel) *Logger

GetLogger returns a pointer to a Logger that logs from logLevel and above. The logger is instructed to include in each log message the name of the service received in input.

func (*Logger) CodeID

func (l *Logger) CodeID(c string) LogChainer

CodeID instructs the logger to log the input code.

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug logs the message at debug level. The log payload will contain everything else the logger has been instructed to log.

func (*Logger) ElapsedTime

func (l *Logger) ElapsedTime(dur time.Duration) LogChainer

ElapsedTime instructs the logger to log the input duration.

func (*Logger) Error

func (l *Logger) Error(msg string, err error)

Error logs the message and the error at error level. The log payload will contain everything else the logger has been instructed to log.

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, err error)

Fatal logs the message and the error at fatal level. It after exits with os.Exit(1). The log payload will contain everything else the logger has been instructed to log.

func (*Logger) Info

func (l *Logger) Info(msg string)

Info logs the message at info level. The log payload will contain everything else the logger has been instructed to log.

func (*Logger) Panic

func (l *Logger) Panic(msg string)

Panic logs the message at panic level. It stops the ordinary flow of a goroutine. The log payload will contain everything else the logger has been instructed to log.

func (*Logger) Signal

func (l *Logger) Signal(s string) LogChainer

Signal instructs the logger to log the input code.

func (*Logger) Warn

func (l *Logger) Warn(msg string)

Warn logs the message at warning level. The log payload will contain everything else the logger has been instructed to log.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL