Categorygithub.com/matthewmueller/logs
repositorypackage
0.0.6
Repository: https://github.com/matthewmueller/logs.git
Documentation: pkg.go.dev

# README

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