Documentation
¶
Overview ¶
Package logging builds the process logger and carries per-unit-of-work attributes through a context.Context.
Setup installs a JSON logger on stdout as the slog default, which also routes the standard library log package through it. With attaches attributes to a context; Handler appends them to every record logged through a *Context method with that context, so a request ID or loan ID set once at the entry point reaches every line below it. When the context carries an OpenTelemetry span, the record also gets its trace_id and span_id.
Index ¶
- Constants
- func Attrs(ctx context.Context) []slog.Attr
- func New(w io.Writer, level slog.Leveler) *slog.Logger
- func ParseLevel(s string) (slog.Level, error)
- func Setup() *slog.Logger
- func With(ctx context.Context, attrs ...slog.Attr) context.Context
- func WithLoan(ctx context.Context, loanID, reference string) context.Context
- type Handler
Constants ¶
const LevelEnv = "LOG_LEVEL"
LevelEnv names the environment variable Setup reads the log level from.
Variables ¶
This section is empty.
Functions ¶
func ParseLevel ¶
ParseLevel parses debug, info, warn or error, case-insensitively. An empty string is info.
func Setup ¶
Setup builds a stdout logger at the level named by LOG_LEVEL, installs it as the slog default and returns it. An unparseable level falls back to info and is reported through the new logger.
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler wraps a slog.Handler and appends the attributes attached to the record's context with With, plus trace_id and span_id when the context carries a valid span.