Simple logger with colors or with JSON.
Tested for race conditions.
Levels:
0 - none,
1 - info,
2 - warn,
3 - debug.
See external testing file.
go test -bench=. -run=^$ . -cpuprofile profile.out
go test -bench=Benchmark_Local_Print_Logger -run=^$ . -cpuprofile profile.out
go test -bench=Benchmark_Local_TimestampNano_Logger -run=^$ . -cpuprofile profile.out
go test -bench=. -benchmem -cpuprofile profile.out
go test -bench=. -benchmem -memprofile memprofile.out -cpuprofile profile.out
go tool pprof profile.out
# with option top, web or pdf
// WithLogger is a logger interface that output logs with a message and key-value pairs.
type WithLogger interface {
Tracew(msg string, keysAndValues ...any)
Debugw(msg string, keysAndValues ...any)
Infow(msg string, keysAndValues ...any)
Warnw(msg string, keysAndValues ...any)
Errorw(msg string, keysAndValues ...any)
Fatalw(msg string, keysAndValues ...any)
Panicw(msg string, keysAndValues ...any)
}
https://dave.cheney.net/2017/01/23/the-package-level-logger-anti-pattern
https://blog.mike.norgate.xyz/unlocking-go-slice-performance-navigating-sync-pool-for-enhanced-efficiency-7cb63b0b453e
https://unskilled.blog/posts/lets-dive-a-tour-of-sync.pool-internals/
https://medium.com/@felipedutratine/profile-your-benchmark-with-pprof-fb7070ee1a94