Documentation
¶
Overview ¶
Package logging provides structured logging setup using Go's standard library log/slog package.
The logging package configures slog with logfmt format (human-readable key=value pairs) and maps string log levels (ERROR, WARNING, INFO, DEBUG, TRACE) to slog levels.
Dynamic log level updates are supported via SetLevel(), which updates the global log level at runtime without requiring logger recreation.
Index ¶
Constants ¶
const ( LevelNameError = "ERROR" LevelNameWarn = "WARN" LevelNameInfo = "INFO" LevelNameDebug = "DEBUG" LevelNameTrace = "TRACE" )
Log level string constants.
const LevelTrace = slog.Level(-8)
LevelTrace is a log level below Debug, used for very verbose diagnostic output. Following slog convention of 4-level gaps: TRACE=-8, DEBUG=-4, INFO=0, WARN=4, ERROR=8.
Variables ¶
This section is empty.
Functions ¶
func NewDynamicLogger ¶
NewDynamicLogger creates a logger with a dynamically adjustable level. The level can be changed at runtime via SetLevel(). Supported levels (case-insensitive): ERROR, WARNING, INFO, DEBUG, TRACE. Invalid levels default to INFO. Uses logfmt format for output.
func NewLogger ¶
NewLogger creates a new structured logger with the specified log level. Supported levels (case-insensitive): ERROR, WARNING, INFO, DEBUG, TRACE. Invalid levels default to INFO. Uses logfmt format for output.
Note: This creates a logger with a static level. For dynamic level updates, use NewDynamicLogger instead.
func ParseLogLevel ¶
ParseLogLevel converts string log level to slog.Level. Returns slog.LevelInfo for invalid or empty levels (safe default). Supported levels (case-insensitive): ERROR, WARNING/WARN, INFO, DEBUG, TRACE.
Types ¶
This section is empty.