Documentation
¶
Overview ¶
Package logger defines the structured logging interface and a global default logger that components use when no explicit logger is configured.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type LogLevel ¶
type LogLevel string
LogLevel is the severity level of a log entry.
const ( // TraceLevel has more verbose messages than DebugLevel. TraceLevel LogLevel = "trace" // DebugLevel is for verbose diagnostic messages. DebugLevel LogLevel = "debug" // InfoLevel is the default log level for informational messages. InfoLevel LogLevel = "info" // WarnLevel is for messages about potential issues. WarnLevel LogLevel = "warn" // ErrorLevel is for error messages indicating a failure. ErrorLevel LogLevel = "error" // FatalLevel is for fatal errors. The program typically exits after logging. FatalLevel LogLevel = "fatal" )
type Logger ¶
type Logger interface {
// WithFields returns a new Logger with the given fields attached to
// every subsequent log entry.
WithFields(map[string]any) Logger
Trace(args ...any)
Tracef(format string, args ...any)
Debug(args ...any)
Debugf(format string, args ...any)
Info(args ...any)
Infof(format string, args ...any)
Warn(args ...any)
Warnf(format string, args ...any)
Error(args ...any)
Errorf(format string, args ...any)
Fatal(args ...any)
Fatalf(format string, args ...any)
// GetLevel returns the current log level.
GetLevel() LogLevel
// IsLevelEnabled reports whether messages at the given level are logged.
IsLevelEnabled(level LogLevel) bool
}
Logger is the structured logging interface. Implementations may write to files, stdout, sockets, or external log services.
func Default ¶
func Default() Logger
Default returns the global default Logger. It may return nil if no default has been set.
func LoggerGroup ¶
LoggerGroup creates a Logger that broadcasts all log calls to the given set of loggers. This is useful for emitting logs to multiple destinations simultaneously (e.g. both a file and stdout).