amseltools/vendor/github.com/lmittmann/tint
Marvin Preuss fafd94b075
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat(logging): from log to slog
2023-04-05 08:24:32 +00:00
..
buffer.go feat(logging): from log to slog 2023-04-05 08:24:32 +00:00
handler.go feat(logging): from log to slog 2023-04-05 08:24:32 +00:00
LICENSE feat(logging): from log to slog 2023-04-05 08:24:32 +00:00
README.md feat(logging): from log to slog 2023-04-05 08:24:32 +00:00

tint: 🌈 slog.Handler that writes tinted logs

Go Reference Go Report Card



Package tint provides a slog.Handler that writes tinted logs. The output format is inspired by the zerolog.ConsoleWriter.

go get github.com/lmittmann/tint

Note

slog is an experimental structured logging package, that will be included in the standard library in Go 1.21. See #56345 for tracking the progress.

Usage

// create a new logger
logger := slog.New(tint.NewHandler(os.Stderr))

// set global logger with custom options
slog.SetDefault(slog.New(tint.Options{
	Level:      slog.LevelDebug,
	TimeFormat: time.Kitchen,
}.NewHandler(os.Stderr)))

Windows

ANSI color support in the terminal on Windows can be enabled by using e.g. go-colorable.

logger := slog.New(tint.NewHandler(colorable.NewColorableStderr()))