Documentation
¶
Overview ¶
Package logger supports logging and tracing based on the standard library package log/slog.
Debug, Error, Info and Warn operate like their package slog equivalents, with the level of logging modifiable using SetLevel.
A custom logging level (LevelTrace) can be supplied to SetLevel to enable tracing. Tracing can be unconditional when calling Trace, or only enabled for pre-defined identifiers when calling TraceID. Identifiers for TraceID are registered by calling SetTraceIDs.
By default, all debug, error, info and warn messages go to Stdout, and traces go to Stderr; these destinations can be changed by calling RedirectNormal and RedirectTrace respectively.
When used in cli applications, a cli.Flag representing a LogLevel can be provided using the LogLevelFlag type.
Index ¶
- func Debug(msg string, args ...any)
- func Error(msg string, args ...any)
- func Info(msg string, args ...any)
- func Level() string
- func RedirectStandard(w io.Writer)
- func RedirectTrace(w io.Writer)
- func SetFormat(f Format)
- func SetLevel(l slog.Level)
- func SetTraceIds(ids ...string)
- func Trace(msg string, args ...any)
- func TraceID(id string, msg string, args ...any)
- func Warn(msg string, args ...any)
- type Format
- type LogLevel
- type LogLevelFlag
- type Traces
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RedirectStandard ¶
RedirectStandard changes the destination for normal (non-trace) logs
func RedirectTrace ¶
RedirectTrace changes the destination for normal (non-trace) logs
func SetTraceIds ¶
func SetTraceIds(ids ...string)
SetTraceIds registers identifiers for future tracing
Types ¶
type LogLevel ¶
type LogLevel int
LogLevel is the level of logging
func (*LogLevel) UnmarshalJSON ¶
UnmarshalJSON is a convenience method for Kong
type LogLevelFlag ¶
LogLevelFlag is useful for using a LogLevel as a command-line flag in CLI applications