Documentation ¶
Overview ¶
Package logger provides a log interface
Index ¶
- Variables
- func Debug(ctx context.Context, msg string, attrs ...interface{})
- func Error(ctx context.Context, msg string, attrs ...interface{})
- func Fatal(ctx context.Context, msg string, attrs ...interface{})
- func Info(ctx context.Context, msg string, attrs ...interface{})
- func Init(opts ...options.Option) error
- func NewContext(ctx context.Context, l Logger) context.Context
- func NewStdLogger(l Logger, level Level) *log.Logger
- func RedirectStdLogger(l Logger, level Level) func()
- func Trace(ctx context.Context, msg string, attrs ...interface{})
- func V(level Level) bool
- func Warn(ctx context.Context, msg string, attrs ...interface{})
- func WithAddSource(v bool) options.Option
- func WithAddStacktrace(v bool) options.Option
- func WithAttrs(attrs ...interface{}) options.Option
- func WithCallerSkipCount(c int) options.Option
- func WithContextAttrFuncs(fncs ...ContextAttrFunc) options.Option
- func WithLevel(lvl Level) options.Option
- func WithMicroKeys() options.Option
- func WithOutput(out io.Writer) options.Option
- func WithSlogKeys() options.Option
- func WithZapKeys() options.Option
- func WithZerologKeys() options.Option
- type ContextAttrFunc
- type Level
- type Logger
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLogger variable DefaultLogger = NewLogger() // DefaultLevel used by logger DefaultLevel = InfoLevel // DefaultCallerSkipCount used by logger DefaultCallerSkipCount = 2 )
var DefaultContextAttrFuncs []ContextAttrFunc
Functions ¶
func NewContext ¶
NewContext stores logger into passed context
func NewStdLogger ¶
NewStdLogger returns new *log.Logger baked by logger.Logger implementation
func RedirectStdLogger ¶
RedirectStdLogger replace *log.Logger with logger.Logger implementation
func WithAddSource ¶ added in v4.0.17
WitAddSource controls writing source file and pos in log
func WithAddStacktrace ¶ added in v4.0.17
WithAddStacktrace controls writing stacktrace on error
func WithCallerSkipCount ¶
WithCallerSkipCount set frame count to skip
func WithContextAttrFuncs ¶ added in v4.0.13
func WithContextAttrFuncs(fncs ...ContextAttrFunc) options.Option
WithContextAttrFuncs appends default funcs for the context arrts filler
func WithMicroKeys ¶ added in v4.0.14
func WithOutput ¶
WithOutput set default output writer for the logger
func WithSlogKeys ¶ added in v4.0.14
func WithZapKeys ¶ added in v4.0.14
func WithZerologKeys ¶ added in v4.0.14
Types ¶
type ContextAttrFunc ¶ added in v4.0.13
type Level ¶
type Level int8
Level means logger level
const ( // TraceLevel level usually used to find bugs, very verbose TraceLevel Level = iota - 2 // DebugLevel level used only when enabled debugging DebugLevel // InfoLevel level used for general info about what's going on inside the application InfoLevel // WarnLevel level used for non-critical entries WarnLevel // ErrorLevel level used for errors that should definitely be noted ErrorLevel // FatalLevel level used for critical errors and then calls `os.Exit(1)` FatalLevel )
func ParseLevel ¶
ParseLevel converts a level string into a logger Level value. returns an InfoLevel if the input string does not match known values.
type Logger ¶
type Logger interface { // Init initialises options Init(opts ...options.Option) error // Clone create logger copy with new options Clone(opts ...options.Option) Logger // V compare provided verbosity level with current log level V(level Level) bool // Level sets the log level for logger Level(level Level) // The Logger options Options() Options // Attrs set attrs to always be logged with keyval pairs Attrs(attrs ...interface{}) Logger // Info level message Info(ctx context.Context, msg string, attrs ...interface{}) // Tracef level message Trace(ctx context.Context, msg string, attrs ...interface{}) // Debug level message Debug(ctx context.Context, msg string, attrs ...interface{}) // Warn level message Warn(ctx context.Context, msg string, attrs ...interface{}) // Error level message Error(ctx context.Context, msg string, attrs ...interface{}) // Fatal level message Fatal(ctx context.Context, msg string, attrs ...interface{}) // Log logs message with needed level Log(ctx context.Context, level Level, msg string, attrs ...interface{}) // String returns the type name of logger String() string // String returns the name of logger Name() string }
Logger is a generic logging interface
func Attrs ¶ added in v4.0.13
func Attrs(attrs ...interface{}) Logger
Attrs create default logger with specific attrs
func FromContext ¶
FromContext returns logger from passed context
type Options ¶
type Options struct { // Out holds the output writer Out io.Writer // Context holds exernal options Context context.Context // TimeFunc used to obtain current time TimeFunc func() time.Time // TimeKey is the key used for the time of the log call TimeKey string // Name holds the logger name Name string // LevelKey is the key used for the level of the log call LevelKey string // MessageKey is the key used for the message of the log call MessageKey string // ErrorKey is the key used for the error info ErrorKey string // SourceKey is the key used for the source file and line of the log call SourceKey string // StacktraceKey is the key used for the stacktrace StacktraceKey string // Attrs holds additional attributes Attrs []interface{} // ContextAttrFuncs contains funcs that executed before log func on context ContextAttrFuncs []ContextAttrFunc // CallerSkipCount number of frmaes to skip CallerSkipCount int // The logging level the logger should log Level Level // AddStacktrace controls writing of stacktaces on error AddStacktrace bool // AddSource enabled writing source file and position in log AddSource bool }
Options holds logger options
func NewOptions ¶
NewOptions creates new options struct