Skip to content

Simple logger for your Go apps. Compatible with slog.

License

Notifications You must be signed in to change notification settings

matthewmueller/logs

Repository files navigation

logs

Go Reference

Simple, pretty logger for your Go apps.

log := logs.Default()
log.WithGroup("grouped").Debug("debug line", "path", "console_test.go")
log.Info("some info")
log.Warn("some warning")
log.Error("an error", "err", errors.New("oh no"))

log screenshot

Features

  • Compatible with slog
  • Pretty console handler for terminals
  • Adds a level filter handler
  • Adds a concurrent multi-logger

Install

go get github.com/matthewmueller/logs

Example

// Go with the default logger
log := logs.Default()

// Or configure
log = logs.New(
  logs.Multi(
    logs.Filter(slog.LevelInfo, logs.Console(os.Stderr)),
    slog.NewJSONHandler(os.Stderr, nil),
  ),
)

log.WithGroup("hello").Debug("world", "args", 10)
log.Info("hello", "planet", "world", "args", 10)
log.Warn("hello", "planet", "world", "args", 10)
log.Error("hello world", "planet", "world", "args", 10)

// Integrates well with other libraries because log is still a *slog.Logger
var logger *slog.Logger = log
logger.WithGroup("hello").Debug("world", "args", 10)
logger.Info("hello", "planet", "world", "args", 10)
logger.Warn("hello", "planet", "world", "args", 10)
logger.Error("hello world", slog.String("planet", "world"), "args", 10)

Contributors

License

MIT

About

Simple logger for your Go apps. Compatible with slog.

Resources

License

Stars

Watchers

Forks

Packages

No packages published