-
-
Notifications
You must be signed in to change notification settings - Fork 220
Open
Description
Heya,
as discussed in #1032 and slack I would like to tackle the refactor from text based standard logger and zap structured logger to a single logger around golangs slog with the goal to simplify logging in Tegola, and moving logging closer to the standard libraries.
Status quo
- The old implementation uses global variables (e.g., logger, level, IsError, etc.) and manual flag management for log level checks
- even though we log structured logs, we do not use structured logging, we put a message in a structured log, that's it.
This approach was necessary 5 years ago, but fell out of time.
Migration stages
Stage 1
- drop
zap
and std logger in favour ofslog
- add a
tracelog
to everyError
log for easier debugging. We achieve this with a custom log handler that adds a stacktrace field and populates it. The custom handler will be passed toslog.SetDefault()
and will become the global logger. - use
slog
inlog.Info
,log.Infof
(...) to keep compatibility and reduce the changes in stage 1 to a minimum - follow
slog
s approach ofInfo
,Debug
,Warn
andError
to keep things simple - Drop
Fatal(f)
.Fatal(f)
is really only anError(f)
with anos.Exit(1)
. Theos.Exit(1)
should be explicit, not implicitly hidden in a fatal log. - Drop
Trace
, it's not being used anyways - logs will go to
os.Stderr
instead ofos.Stdout
, use one output for simplicity.
Stage 2
- drop
log.Debug, log.Infof
and the likes - modules will either import and use
slog.Default()
, that at this point is out custom logger, - or they receive the logger via dependency injection.
- Module-specific loggers can be derived by adding context using
With
orWithGroup
.
Can we agree on this? :)
gdey
Metadata
Metadata
Assignees
Labels
No labels