- Best options for logging (and why)
- Add enough context to solve problems
- Only configure logging in the last mile (eg. main method)
- eg.
zerolog.SetGlobalLevel(zerolog.DebugLevel)
- eg.
- Use Error/Warn logging generously since this helps resolve issues
- Use Info/Debug logging sparingly, replace with tests
- Less spam in the code
- Code executes faster
- Tests should cover cases where this logging would be useful
Best: zap
- More complex than zerolog, wider scope, more features
- More compatible with Opentelemetry
- Avoid the sugar api
- Uses reflection
- No type safety (so no refactoring)
- Slower than the typesafe api
- Error prone: Developer must carefully pair
keys
andvalues
- zap setup examples
- OpenTelemetry & Zap integration
Next Best: zerolog
- Use if zap doesn't meet your needs
- Simple
- Fast
- Comprehensive for typical cases
Con
: incompatible with OpenTelemetryCon
: seems to be unmaintained- zerolog setup examples