Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 1.51 KB

logging.md

File metadata and controls

43 lines (35 loc) · 1.51 KB

Overview

  • Best options for logging (and why)

Idioms

  1. Add enough context to solve problems
  2. Only configure logging in the last mile (eg. main method)
    1. eg. zerolog.SetGlobalLevel(zerolog.DebugLevel)
  3. Use Error/Warn logging generously since this helps resolve issues
  4. Use Info/Debug logging sparingly, replace with tests
    1. Less spam in the code
    2. Code executes faster
    3. Tests should cover cases where this logging would be useful

Best: zap

  1. More complex than zerolog, wider scope, more features
  2. More compatible with Opentelemetry
  3. Avoid the sugar api
    1. Uses reflection
    2. No type safety (so no refactoring)
    3. Slower than the typesafe api
    4. Error prone: Developer must carefully pair keys and values
  4. zap setup examples
  5. OpenTelemetry & Zap integration

Next Best: zerolog

  1. Use if zap doesn't meet your needs
  2. Simple
  3. Fast
  4. Comprehensive for typical cases
  5. Con: incompatible with OpenTelemetry
  6. Con: seems to be unmaintained
  7. zerolog setup examples

Other Resources

  1. https://pkg.go.dev/github.com/rs/zerolog
  2. https://github.com/rs/zerolog
  3. https://medium.com/swlh/stop-using-prints-and-embrace-zerolog-2c4dd8e8816a
  4. https://learning-cloud-native-go.github.io/docs/a6.adding_zerolog_logger/
  5. https://godocs.io/github.com/rs/zerolog