Documentation
¶
Overview ¶
Package slogx wraps log/slog with convenience helpers so callers only need a single import for structured logging.
It re-exports the most commonly used slog types and functions, adds context-based logger passing, format configuration (JSON, pretty, text), and a small set of attribute helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( String = slog.String Int = slog.Int Int64 = slog.Int64 Bool = slog.Bool Float64 = slog.Float64 Duration = slog.Duration Time = slog.Time Any = slog.Any Group = slog.Group )
Re-export common slog attribute constructors.
Functions ¶
func FromContext ¶
FromContext retrieves a logger from the context. Returns slog.Default() if none is set.
Types ¶
type Format ¶
type Format int
Format selects the log output format.
func (Format) MarshalText ¶
func (Format) String ¶
String and Set make Format a flag.Value; both delegate to MarshalText / UnmarshalText so the accepted values and output are consistent.
func (*Format) UnmarshalText ¶
type Level ¶
Level is a named slog level that implements flag.Value and encoding.TextMarshaler / encoding.TextUnmarshaler, mirroring how Format works so callers can register it directly with flag parsing libraries.
It also implements slog.Leveler so it can be passed to slog.HandlerOptions.Level and similar interfaces.
const ( LevelDebug Level = Level(slog.LevelDebug) LevelInfo Level = Level(slog.LevelInfo) LevelWarn Level = Level(slog.LevelWarn) LevelError Level = Level(slog.LevelError) )
Re-export slog levels so callers don't need to import both packages.
func (Level) MarshalText ¶
func (Level) String ¶
String and Set make Level a flag.Value; both delegate to MarshalText / UnmarshalText so the accepted values and output are consistent.