Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithLogger(ctx context.Context, l Logger) context.Context
- func Debug(ctx context.Context, msg string)
- func Error(ctx context.Context, msg string)
- func Fatal(ctx context.Context, msg string)
- func Info(ctx context.Context, msg string)
- func Warn(ctx context.Context, msg string)
- type Fields
- type Level
- type Logger
- type Params
Constants ¶
View Source
const ( // LevelDebug is a debug level. LevelDebug = slog.LevelDebug // LevelInfo is an info level. LevelInfo = slog.LevelInfo // LevelWarn is a warn level. LevelWarn = slog.LevelWarn // LevelError is an error level. LevelError = slog.LevelError // LevelFatal is a fatal level. LevelFatal = slog.Level(12) )
Variables ¶
View Source
var AllLevels = []Level{ LevelDebug, LevelInfo, LevelWarn, LevelError, LevelFatal, }
AllLevels is a slice of all levels.
Functions ¶
func ContextWithLogger ¶
ContextWithLogger adds Logger to context and returns new context.
func Debug ¶
Debug prints debug-level log message. Usually very verbose and shown only when debug level is enabled.
Types ¶
type Level ¶ added in v0.4.0
Level type.
func ParseLevel ¶ added in v1.0.0
ParseLevel takes a string level and returns the Logrus log level constant.
type Logger ¶
type Logger interface {
Debug(msg string)
Info(msg string)
Warn(msg string)
Error(msg string)
Fatal(msg string)
WithError(err error) Logger
WithField(key string, value interface{}) Logger
WithFields(fields Fields) Logger
}
Logger serves as an adapter interface for logger libraries so that we not depend on any of them directly.
func FromContext ¶
FromContext extracts Logger from context. If no instance found - returns Logger from default logInstance.
func Init ¶
Init initiates logger and add format options. Should be called only once, on start of app.
type Params ¶
type Params struct {
// Writer is a writer to write logs to. By default, it's os.Stderr.
Writer io.WriteCloser
// Level is one of "debug", "info", "warn", "error", "fatal".
Level string
// Format is one of "json" or "text".
Format string
// WithSource enables source code info in logs.
WithSource bool
}
Params holds logger specific params.
Click to show internal directories.
Click to hide internal directories.