zlog aims to provide a consistent, easy to use structured logging interface.
The interface is inspired by zerolog and uses it for the default implementation that provides JSON.
zlog's API mimics the chaining API style from zerolog and logrus to provide a simple intuitive interface to the developers while allowing high performance implementations avoiding reflection and allocations.
Refer complete documentation : https://godoc.org/github.com/anuvu/zlog
- Context based logging
- Log level support
- Near-zero allocations
import "github.com/anuvu/zlog"
log.Info().Msg("hello world")
// Output: {"level":"info","time":1494567715,"message":"hello world"}log.Info().Str("foo", "bar").Int("n", 123).Msg("hello world")
// Output: {"level":"info",foo":"bar","n":123,"message":"hello world"}logger := zlog.New("test_logger").With().Timestamp().Logger()
logger.Info().Str("foo", "bar").Msg("hello world")
// Output: {"level":"info","time":1494567715,"message":"hello world","foo":"bar"}sublogger := log.With().Str("component": "foo").Logger()
sublogger.Info().Msg("hello world")
// Output: {"level":"info","time":1494567715,"message":"hello world","component":"foo"}log := zlog.New("test_logger").With().Str("foo", "bar").Logger()
stdlog.SetFlags(0)
stdlog.SetOutput(log)
stdlog.Print("hello world")
// Output: {"foo":"bar","message":"hello world"}StrBoolIntUintFloat32
Error: Takes anerrorand render it as a string using theerrorfield name.Timestamp: Insert a timestamp field withtimefield name and formatted using RFC 3339 format.
$ go test -bench=. -benchmem
.........
9 total assertions
goos: darwin
goarch: amd64
pkg: github.com/anuvu/zlog
BenchmarkLogEmpty-8 50000000 31.2 ns/op 0 B/op 0 allocs/op
BenchmarkDisabled-8 200000000 6.37 ns/op 0 B/op 0 allocs/op
BenchmarkInfo-8 30000000 50.7 ns/op 0 B/op 0 allocs/op
BenchmarkContextFields-8 10000000 143 ns/op 0 B/op 0 allocs/op
BenchmarkContextAppend-8 10000000 150 ns/op 832 B/op 3 allocs/op
BenchmarkLogFields-8 10000000 229 ns/op 0 B/op 0 allocs/op
BenchmarkLogFieldType/Int-8 30000000 49.1 ns/op 0 B/op 0 allocs/op
BenchmarkLogFieldType/Str-8 30000000 43.7 ns/op 0 B/op 0 allocs/op
BenchmarkLogFieldType/Err-8 30000000 49.5 ns/op 0 B/op 0 allocs/op
BenchmarkLogFieldType/Object-8 10000000 109 ns/op 64 B/op 2 allocs/op
BenchmarkLogFieldType/Bool-8 30000000 43.2 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/anuvu/zlog 17.846s