logger is a fast Go logging package made to be simple but effective.
Install with:
go get github.com/hamba/logger/v2
- JSON
- Logfmt
- Console
- SyncWriter Write synchronised to a Writer
Note: This project has renamed the default branch from master
to main
. You will need to update your local environment.
log := logger.New(os.Stdout, logger.LogfmtFormat(), logger.Info)
// Logger can have scoped context
log = log.With(ctx.Str("env", "prod"))
// All messages can have a context
log.Warn("connection error", ctx.Str("redis", "dsn_1"), ctx.Int("timeout", conn.Timeout()))
Will log the message
lvl=warn msg="connection error" env=prod redis=dsn_1 timeout=0.500
More examples can be found in the godocs.