Skip to content

hamba/logger

Repository files navigation

Logo

Go Report Card Build Status Coverage Status Go Reference GitHub release GitHub license

logger is a fast Go logging package made to be simple but effective.

Overview

Install with:

go get github.com/hamba/logger/v2

Formatters

  • JSON
  • Logfmt
  • Console

Writers

  • 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.

Examples

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.