prebid-server icon indicating copy to clipboard operation
prebid-server copied to clipboard

Switch from glog to slog for structured (as well as leveled) logging

Open scr-oath opened this issue 1 year ago • 4 comments

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 \n for 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)

scr-oath avatar Dec 13 '24 07:12 scr-oath

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*

linux019 avatar Jan 24 '25 15:01 linux019

This is actively being discussed in the Go engineering meetings right now.

Net-burst avatar May 30 '25 14:05 Net-burst

Driven by community. Progressing quite steadily.

Net-burst avatar Jul 11 '25 14:07 Net-burst

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

bsardo avatar Oct 16 '25 13:10 bsardo