Package zlog provides a minimal setup for log/slog with sensible defaults.
package main
import (
"flag"
"log/slog"
"zuern.dev/zlog"
)
func main() {
level := zlog.RegisterLevelFlag(flag.CommandLine)
flag.Parse()
zlog.Init(level)
slog.Info("service started", slog.String("version", "1.2.3"))
}The handler format is selected in this order:
LOG_FORMAT=jsonorLOG_FORMAT=textif set.- Otherwise, text format when stderr is a TTY and JSON when it is not.
The pretty text handler in prettylog is derived from
dusted-go/logging's handlers/prettylog and is licensed under
Apache 2.0. See https://github.com/dusted-go/logging/tree/main/handlers/prettylog.