Documentation
¶
Overview ¶
Package logging provides log/slog handlers with an established human-readable line format:
2006/01/02 15:04:05 [LEVEL] [service] file.go:42 - message | key=value
It is stdlib-only, and it is a handler package rather than a logger API: applications use the standard *slog.Logger on top, so nothing here is a dependency they cannot walk away from. New wires a logger from the conventional environment variables (LOG_LEVEL, LOG_FORMAT=json for machine-readable output, NO_COLOR / LOG_NO_COLOR).
The printf-style helpers -- InitializeGlobalLogger plus Debug/Info/Warn/Error/Fatal -- are a thin, stateless convenience over slog's default logger for code that has not moved to structured attributes. They hold no state and return nothing; ignoring them costs nothing.
Index ¶
- func Debug(msg string, args ...any)
- func Error(msg string, args ...any)
- func Fatal(msg string, args ...any)
- func Info(msg string, args ...any)
- func InitializeGlobalLogger(serviceName string)
- func LevelFromEnv() slog.Level
- func New(service string) *slog.Logger
- func Warn(msg string, args ...any)
- type Handler
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitializeGlobalLogger ¶
func InitializeGlobalLogger(serviceName string)
InitializeGlobalLogger installs the service's logger as slog's default. Configuration comes from LOG_LEVEL, LOG_FORMAT and NO_COLOR/LOG_NO_COLOR.
func LevelFromEnv ¶
LevelFromEnv parses LOG_LEVEL into a slog.Level, defaulting to Info.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a slog.Handler emitting the platform line format.
func NewHandler ¶
NewHandler creates a Handler with the given options.
type Options ¶
type Options struct {
// Service names the emitting service in every line.
Service string
// Level is the minimum level to emit.
Level slog.Leveler
// Colors enables ANSI level colors.
Colors bool
// Writer receives the output; defaults to os.Stdout.
Writer io.Writer
}
Options configures a Handler.