feat(diary): channels, components and config/log.yaml

- stderr and null drivers; per-component levels from log.components
- SUMMER_LOG__ overrides parse as strings and overlay the defaults key by key
- Validation names the key: driver, format, level, days, stack children and cycles, daily path outside the root
- summer new writes config/log.yaml (stack of console and daily, river warn, http info)
- docs/services/logging.md: channels, config/log.yaml, component loggers, daily files, redaction
- Log keys in the configuration docs; ExampleFor backs the docs snippet
This commit is contained in:
Jakub Zych
2026-10-21 11:48:25 +02:00
parent e903cc32be
commit 5b09b32512
16 changed files with 445 additions and 43 deletions

View File

@@ -48,9 +48,10 @@ type channelBuilder struct {
warnTo slog.Handler
}
// buildChannels builds the channel named by cfg.Default. Every leaf is
// wrapped by sunscreen.Wrap and gated by its own level; a stack fans out
// through slog.NewMultiHandler.
// buildChannels builds the channel named by cfg.Default. Every leaf
// (console, stderr, daily and null) is wrapped by sunscreen.Wrap and gated by
// its own level; a stack fans out through slog.NewMultiHandler. A relative
// daily path resolves against Options.Root.
func buildChannels(cfg Config, opts Options) (*channels, error) {
b := &channelBuilder{
cfg: cfg,
@@ -115,6 +116,16 @@ func (b *channelBuilder) build(name string) (slog.Handler, error) {
b.warnTo = wrapped
}
return wrapped, nil
case DriverStderr:
var leaf slog.Handler
if ch.Format == FormatJSON {
leaf = slog.NewJSONHandler(b.opts.Stderr, hopts)
} else {
leaf = slog.NewTextHandler(b.opts.Stderr, hopts)
}
return sunscreen.Wrap(leaf), nil
case DriverNull:
return sunscreen.Wrap(slog.DiscardHandler), nil
case DriverDaily:
path := ch.Path
if !filepath.IsAbs(path) {