prebid-server
prebid-server copied to clipboard
Switch from glog to slog for structured (as well as leveled) logging
slog wins
- slog is now part of the SDK, maintained by the language owners
- slog has support for OpenTelemetry bridging
- slog has json format and, can log any structure in attributes
- There are some nice libraries already https://github.com/samber/slog-multi and https://github.com/samber/slog-sampling e.g. to duplicate, route, or sample logs.
glog shortcomings
- glog has issue with write size - it converts newlines to
\nfor only as big as will fit in its buffer; beyond that, all newlines are as-is and cause multiple, disjoint, possibly interleaved lines to be written. - glog's format does not support things like json for log collectors (like google cloud observability suite, that can query them with BigQuery log analytics)
Why not choose most popular logger from these ones? https://github.com/uber-go/zap 22K stars (it's best and allows to attach any sinks eg stdout, UDP writer etc) https://github.com/rs/zerolog 11K slog - 416*
This is actively being discussed in the Go engineering meetings right now.
Driven by community. Progressing quite steadily.
Discussed and approved. Ready for dev.
PHASE 1:
- interface with just the nonstructured logging functions (call it Error, Warning, Info, etc)
- swap out all calls to glog library with the nonstructured logging function calls from the glog concrete implementation
PHASE 2 (should span multiple smaller PRs):
- host config option to choose logger type (just glog or slog, glog is the default)
- expand interface to include structured logging functions (ErrorS, WarningS, InfoS etc)
- add slog concrete implementation that implements the interface structured logging functions
- add shim so nonstructured calls when slog is enabled are converted to structured logging and vice versa
- slog conversion to text just sprintf msg
- glog conversion to structured (TBD)
- going forward, authors can either call the glog or the slog function
PHASE 3: (breaking change - major version bump - probably a year from now)
- convert all glog calls to slog calls