Migrate internal/log from apex/log to log/slog #77
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
The Go style guide: "Use
log/slogfor structured logging. Importsneak.berlin/go/simplelogfor sensible defaults."internal/log/log.gois built ongithub.com/apex/logpluspterm. Itspackage doc says so outright: "provides leveled logging with progress output
helpers on top of apex/log and pterm".
go.modcarriesgithub.com/apex/log v1.9.0, and every logging call in the codebase routesthrough it.
This is a third-party dependency doing a job the standard library has done
since Go 1.21. Beyond the policy,
apex/logis effectively unmaintained,and shipping a 1.0 library that drags it into every consumer's dependency
graph is a cost imposed on everyone who imports
mfer.This is the largest single item in the 1.0 backlog and it is deliberately
scoped as its own unit.
Definition of done
internal/logis implemented onlog/slog, withsneak.berlin/go/simplelogused for defaults.github.com/apex/logis gone fromgo.modandgo.sum, andgo mod tidyhas been run.
Levelenum,
Progressf/ProgressDoneline-overwrite helpers — either survivesunchanged or changes deliberately, with every call site updated. Callers
outside
internal/logshould not need to care.--verboseand--quietbehave asbefore, progress lines still overwrite in place on a TTY, and the banner
output is preserved or its removal is called out explicitly.
internal/log/log_test.gostill pass and are extended tocover level filtering and the progress helpers against the new backend.
make checkpasses with-race.TODO.mdupdated in the same commit.Implementation requirements
pterm. It is a separate concern fromthe logging backend (it does the terminal rendering), and it may be
legitimate to keep it for progress output while moving leveled logging to
slog. State the decision in the commit message; do not silently keep orsilently drop it.
slog's handler model does not natively do in-place line overwriting.Progress output is a terminal-rendering concern, not a log-record concern —
do not force it through a
slog.Handlerjust to keep it in one place.serializes CLI runs behind a mutex because of it. Do not make that worse.
If the migration lets the logger become an injected dependency rather than
a global, that is a real improvement — but only if it does not balloon
this PR. If you leave it global, say why.
-race. A logging rewrite touching a process-global isexactly where races appear.
audited separately.
unrelated code, stop and report back rather than expanding scope.
(closes #77).