Yet another Go logging library.
Optimized for convenience, typing, compatibility.
Features:
- Built on top of
slog(introduced in Go 1.21, see Go blog)- All handlers and utils can be wrapped with a
*slog.Loggeror other logger frontends, for logging compatibility with projects that do not useproto-log/log.Logger.
- All handlers and utils can be wrapped with a
- Extended
Loggerinterface:Trace,TraceContext:Crit,CritContext: withoutos.Exit, instead attach aPostHandlerModto follow-up crit logs with your preferred crit handling.Contextto access the default contextWithContextto make a logger clone and attach a new default context
- Handler
Unwrappattern, to find handler-wrappers easily - A set of
HandlerModto adjust log-handlers of (sub-)loggers at runtime:ContextModto adjust the defaultcontextLevelModto adjust the log-levelCapturingModto capture loggingPostProcessModto post-process log records (e.g. handle special log levels)
- A set of
slog.Handlerimplementations:DiscardHandlerJSONHandlerLogfmtHandler: for human-readable but Loki-compatible logging.TerminalHandler:- Like logfmt, but stylish, with automatic source-filepath and field padding.
- Looks for
TerminalString() stringon types for custom formatting. uint64,*big.Intand*uint256.Intare logged with_thousand-separators.
TestLogger: minimal test log-handling stack on top ofT.Output()(introduced in Go 1.23)- Can be customized with additional
HandlerMod Logger.Crit/Logger.CritContextare followed up withT.FailNow()
- Can be customized with additional
FormatOptionto configure formatting of handlers:- Option to exclude time, for logging in Go
Exampleoutput to be stable - Option to resolve file-paths of source-file data to relative paths
- Option to color output of
TerminalHandler
- Option to exclude time, for logging in Go
- No dependencies
See: Log example tests
Some other log libraries influenced this:
log15v1 (obligatory xkcd):- Originally introduced in go-ethereum.
- Pushed forward Go structured log fields, sub-logger contexts.
- Influenced terminal log-formatting in go-ethereum / optimism / others (see notice in
format.go).
- Logging was adapted in optimism:
- Optimism introduced initial log-capturer (forked now).
- First version of handler-wrapping idea for composition.
- MIT, see
LICENSEentry.
slogwas introduced in Go 1.21.- Go finally got standard modern structured logging.
- Introduced into go-ethereum.
- Reduced code, adopted standard log-level values and utils.
MIT License, see LICENSE file.