Documentation ¶
Overview ¶
Package logs provides structured JSON logging with arbitrary data. It supports contexts and can extract values from these.
Index ¶
- Constants
- Variables
- func ContextWithLogger(ctx context.Context, logger Logger) context.Context
- func Debug(str string, data interface{}) error
- func Error(str string, data interface{}) error
- func Info(str string, data interface{}) error
- func Log(logLevel LogLevel, str string, data interface{}) error
- func Warning(str string, data interface{}) error
- type LogLevel
- type Logger
- func (l Logger) Debug(str string, data interface{}) error
- func (l Logger) Error(str string, data interface{}) error
- func (l Logger) Info(str string, data interface{}) error
- func (l Logger) Log(logLevel LogLevel, str string, data interface{}) error
- func (l Logger) Warning(str string, data interface{}) error
- func (l Logger) WithContext(ctx context.Context) Logger
- func (l Logger) WithContextKey(contextKey interface{}, messageKey string) Logger
- func (l Logger) WithLogLevel(logLevel LogLevel) Logger
- func (l Logger) WithWriter(w io.Writer) Logger
Constants ¶
const ( LogLevelDebug = LogLevel(iota) LogLevelInfo LogLevelWarning LogLevelError )
Variables ¶
var ( // DefaultLogger logs to the standard output, filtering out debug // messages, and uses the background context. DefaultLogger = Logger{ // contains filtered or unexported fields } )
Functions ¶
func ContextWithLogger ¶ added in v1.1.0
ContextWithLogger creates a new context holding a given logger. The logger can be retrieved with LoggerFromContextOrDefault.
Types ¶
type LogLevel ¶
type LogLevel uint
LogLevel represents a level of logging: the Logger is setup with one and will only log messages with a log level superior or equal to its own.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger logs messages to an io.Writer in JSON format, possibly extracting values from its Context.
func LoggerFromContextOrDefault ¶ added in v1.1.0
LoggerFromContextOrDefault gets a Logger from the current context if there is one. Otherwise it returns the default logger.
func (Logger) Log ¶
Log logs a message as specified by the Logger. Each message is output as a JSON object with `str' in the "message" field, `data' in the "data" field (if not nil) and values from the context in "context".
func (Logger) WithContext ¶
WithContext returns a new Logger with the given context.
func (Logger) WithContextKey ¶
WithContextKey returns a new Logger which will extract from the context the value at `contextKey' and output it under `messageKey' in the JSON message.
func (Logger) WithLogLevel ¶
WithLogLevel returns a new Logger with the given log level.