logger

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FastLogger

type FastLogger struct {
	// contains filtered or unexported fields
}

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

func GetConsoleLogger

func GetConsoleLogger(service string, logLevel LogLevel) *FastLogger

GetConsoleLogger returns a pointer to a Logger that logs from logLevel and above to standard output in colorised human readable format. The logger is instructed to include in each log message the name of the service received in input.

func GetLogger

func GetLogger(service string, logLevel LogLevel) *FastLogger

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 GetLoggerString

func GetLoggerString(service string, logLevel string) *FastLogger

GetLoggerString - alternative Logger constructor that returns a pointer to a Logger based on a string defining a log level. The default value is INFO.

func (*FastLogger) BytesWritten added in v0.2.0

func (l *FastLogger) BytesWritten(bw int) Logger

BytesWritten instructs the logger to log the bytes written.

func (*FastLogger) Debug

func (l *FastLogger) 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 (*FastLogger) Duration added in v0.2.0

func (l *FastLogger) Duration(d time.Duration) Logger

Duration instructs the logger to log the duration.

func (*FastLogger) Error

func (l *FastLogger) 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 (*FastLogger) Event

func (l *FastLogger) Event(e string) Logger

Event instructs the logger to log the event.

func (*FastLogger) Fatal

func (l *FastLogger) 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 (*FastLogger) Host added in v0.2.0

func (l *FastLogger) Host(h string) Logger

Host instructs the logger to log the host.

func (*FastLogger) Info

func (l *FastLogger) 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 (*FastLogger) Method added in v0.2.0

func (l *FastLogger) Method(m string) Logger

Method instructs the logger to log the method.

func (*FastLogger) Panic

func (l *FastLogger) 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 (*FastLogger) RemoteAddr added in v0.2.0

func (l *FastLogger) RemoteAddr(addr string) Logger

RemoteAddr instructs the logger to log the remote address.

func (*FastLogger) RequestID

func (l *FastLogger) RequestID(id string) Logger

RequestID instructs the logger to log the request ID.

func (*FastLogger) Signal

func (l *FastLogger) Signal(sig fmt.Stringer) Logger

Signal instructs the logger to log the signal.

func (*FastLogger) StatusCode

func (l *FastLogger) StatusCode(sc int) Logger

StatusCode instructs the logger to log the status code.

func (*FastLogger) URI added in v0.2.0

func (l *FastLogger) URI(uri string) Logger

URI instructs the logger to log the URI.

func (*FastLogger) UserAgent added in v0.2.0

func (l *FastLogger) UserAgent(ua string) Logger

UserAgent instructs the logger to log the user agent.

func (*FastLogger) Warn

func (l *FastLogger) Warn(msg string)

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

type LogKey

type LogKey string

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

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 level logging
	DEBUG LogLevel = iota
	// INFO level logging
	INFO
	// WARNING level logging
	WARNING
	// ERROR level logging
	ERROR
	// FATAL level logging
	FATAL
	// PANIC level logging
	PANIC
	// DISABLED level logging
	DISABLED
)

func ParseLogLevel

func ParseLogLevel(level string) LogLevel

ParseLogLevel parses the input string and returns the respective log level.

type Logger

type Logger interface {
	BytesWritten(int) Logger
	Duration(time.Duration) Logger
	Host(string) Logger
	Method(string) Logger
	Event(string) Logger
	RequestID(string) Logger
	RemoteAddr(string) Logger
	StatusCode(int) Logger
	Signal(fmt.Stringer) Logger
	URI(string) Logger
	UserAgent(string) Logger

	// 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)
}

Logger 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).

Jump to

Keyboard shortcuts

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