Logging framework
Need to finalize which golang logging framework to use. Logging in Go: A Comparison of the Top 9 Libraries is an excellent overview of current options.
Phuslu/log Zerolog Zap
we can pick from these 3
I have used Zerolog extensively with no issues or observed performance penalties.
Zerolog: +1
Here is a sample Zerolog configuration along with the output:
logger := zerolog.New(
zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.RFC3339},
).Level(zerolog.TraceLevel).With().Timestamp().Caller().Logger()
logger.Debug().Msg("Debugging...")
logger.Trace().Msg("Tracing...")
logger.Warn().Msg("Warning...")
logger.Error().Msg("Error...")
which results in the following output
this looks fine.
We can use zerolog then
Seems I'm a bit late for party, please allow me do self-recommandation, The article "Logging in Go: A Comparison of the Top 9 Libraries" is a bit unfair for phuslu/log, in our internal system (Yes, I am also a bidding system author), my logger is more suitable becuase
- phuslu/log is 0-allocs in printf style logging, others are at least 1-allocs
- phuslu/log is 0-allocs in runtime.Caller cases, others are at least 3-allocs, and much much slower.
- phuslu/log is 0-allocs in Any/Interface cases, others are at least 1-allocs
- phuslu/log filewriter has linux writerv support, this is only one of golang world, resulting 10x faster in heavy-load cases.
- phuslu/log console field is ordered, it's hard in zerolog, see https://github.com/rs/zerolog/issues/155#issuecomment-2094274149
- phuslu/log is the fastest (and much faster) in stdlog slog implementation, see https://madkins23.github.io/go-slog/index.html
Finally, as a log library invented because of the bidding system, please believe me that this implementation is the most suitable.