Documentation
¶
Index ¶
- func Component(name string) *slog.Logger
- func ComponentWithContext(ctx context.Context, component string) *slog.Logger
- func Default() *slog.Logger
- func DiscardLogger() *log.Logger
- func FromContext(ctx context.Context) *slog.Logger
- func Setup(cfg Config)
- func ShouldLogSuppressible() bool
- func ShouldLogVerbose() bool
- func StdLogger(component string) *log.Logger
- func WithContext(logger *slog.Logger, ctx context.Context) *slog.Logger
- type Config
- type Verbosity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Component ¶
Component returns a logger with a "component" attribute set to the given name. Use this to create component-specific loggers for structured logging.
func ComponentWithContext ¶
ComponentWithContext returns a logger with both component and trace_id attributes. This is the recommended way to create component-specific loggers.
Usage:
log := logging.ComponentWithContext(ctx, "storage")
log.Info("bucket created", "bucket", "my-bucket")
The log will include both component="storage" and trace_id from context.
func Default ¶
Default returns the default logger. If Setup has not been called, returns slog's default logger.
func DiscardLogger ¶
DiscardLogger returns a standard library logger that discards all output. Use this for noisy third-party libraries that should be silenced.
func FromContext ¶
FromContext returns a logger with the trace_id automatically included from context. This is the recommended way to get a logger - it ensures trace_id is never forgotten.
Usage:
log := logging.FromContext(ctx)
log.Info("operation completed", "details", "some info")
The trace_id will be automatically included in the log output.
func Setup ¶
func Setup(cfg Config)
Setup initializes the global logger with the given configuration. This should be called once at application startup.
func ShouldLogSuppressible ¶
func ShouldLogSuppressible() bool
ShouldLogSuppressible returns true if suppressible messages should be logged. Suppressible messages are routine/noisy messages that can be hidden in quiet mode. Returns false only when verbosity is "quiet".
func ShouldLogVerbose ¶
func ShouldLogVerbose() bool
ShouldLogVerbose returns true if verbose messages should be logged. Verbose messages are extra diagnostic output only shown in verbose mode. Returns true only when verbosity is "verbose".
Types ¶
type Config ¶
type Config struct {
Level string // debug, info, warn, error
Format string // text, json
Verbosity string // quiet, normal, verbose
Output io.Writer // defaults to os.Stderr
}
Config holds logger configuration
type Verbosity ¶
type Verbosity int
Verbosity represents the chattiness level of log output. This is separate from log levels (debug, info, warn, error) - verbosity controls how much detail components output at any given level.
func ParseVerbosity ¶
ParseVerbosity converts a string to a Verbosity level. Accepts "quiet", "normal", or "verbose". Defaults to VerbosityNormal.