Overview
A small slog wrapper that composes handlers for filtering, fan-out, and two custom levels.
log is a thin layer over the standard library's log/slog. Everything it builds is an ordinary slog.Handler, so it composes with the stdlib and any other handler you already use, and it has zero dependencies. On top of slog it adds a small builder, log.New, that assembles outputs, a level, and filters without hand-wiring handlers. It also adds record filtering, fan-out to several outputs at once, and two custom levels (TRACE below DEBUG and FATAL above ERROR) rendered with their names.
Install
go get github.com/toaweme/logGetting started
For app code that only needs to log, use the package-level helpers. They write text to stdout at DEBUG with no setup.
log.Info("server", "port", 8080)
log.Error("request", "err", err)
log.Trace("entered", "i", i)
log.SetLevel(slog.LevelInfo) // raise the threshold on the default loggerWhen you are ready to inject a logger instead of reaching for the global, build one with log.New. With no options it writes text to stdout at DEBUG. Pass as many outputs as you like and they fan out automatically.
logger := log.New(
log.WithText(os.Stdout),
log.WithLevel(slog.LevelInfo),
)
logger.Info("ready")
logger = logger.With("svc", "api") // every record now carries svc=apilog.Logger is the interface you pass around. It is itself a slog.Handler, so it drops into anything that expects one.
Note
log never chooses your outputs or opens files for you. You hand it the writers and handlers, so the package stays free of any assumption about where logs go.
Where to go next
Start with the guides to learn how each piece behaves, then reach for the reference when you need the exact signature.
log.New, inject the Logger interface, and install a process-wide default.FilteringDrop noisy records or shorten fat attribute values by level, message, or attribute match.Fan-out and levelsSend one record to several outputs at once, and use the custom TRACE and FATAL levels.ReferenceThe logger and its options, the filter builders, and the handler primitives.