repositorypackage
0.0.7
Repository: https://github.com/jasonhancock/go-logger.git
Documentation: pkg.go.dev
# README
go-logger
This is a fork of the logger from gmkit.
A structured, leveled logger. Output is logfmt by default.
Usage
Minimal configuration
l := logger.New()
l.Info("some message", "anotherkey", "another value")
// Output would resemble:
// ts=2023-04-21T16:09:00.026753Z caller=github.com/jasonhancock/go-logger_test/example_test.go:43 src=go-logger.test level=info msg="some message" anotherkey="another value"
Customized config
l := logger.New(
logger.WithDestination(os.Stdout),
logger.WithName("myapp"),
logger.WithLevel("info"),
logger.WithFormat(logger.FormatLogFmt),
logger.With("somekey", "someval"),
)
l.Info("some message", "anotherkey", "another value")
// Output would resemble:
// ts=2023-04-13T17:38:13.516398Z caller=github.com/jasonhancock/go-logger_test/example_test.go:11 somekey=someval src=myapp level=info msg="some message" anotherkey="another value"
JSON
l := logger.New(
logger.WithFormat(logger.FormatJSON),
logger.WithName("myapp"),
)
l.Info("some message", "anotherkey", "another value")
// Output would resemble:
// {"anotherkey":"another value","caller":"github.com/jasonhancock/go-logger_test/example_test.go:32","level":"info","msg":"some message","src":"myapp","ts":"2023-04-21T16:08:24.224597Z"}
Using the default logger
l := logger.Default()
l.Info("some message")
// Output would resemble:
// ts=2023-04-21T16:09:28.653472Z caller=github.com/jasonhancock/go-logger_test/example_test.go:51 src=default level=info msg="some message"