Skip to content

refactor(logging): migrate from logrus to log/slog - #35

Open
sbldevnet wants to merge 2 commits into
mainfrom
refactor/logging-slog
Open

sbldevnet wants to merge 2 commits into
mainfrom
refactor/logging-slog

Conversation

@sbldevnet

@sbldevnet sbldevnet commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces logrus (global logger + logger.X(funcName, fmt, args...) package functions) with log/slog: a plain logger.New() *slog.Logger constructor, threaded explicitly through every function that logs instead of a package-level global.
  • LOG_LEVEL / LOG_FORMAT env vars keep controlling level and format exactly as before, including the fallback to info with a warning on an invalid LOG_LEVEL.
  • Drops github.com/sirupsen/logrus entirely.

Behavior change

  • The unused trace log level goes away (nothing in production code called it, and slog has no built-in trace level). LOG_LEVEL=trace now falls back to info with a warning like any other invalid value.

Test plan

  • go build ./... / go vet ./...
  • go test -race ./...
  • Manual check: LOG_LEVEL=debug run → readable text logs on stderr
  • Manual check: LOG_FORMAT=json LOG_LEVEL=debug run → one JSON object per line
  • go list -m all | grep sirupsen → no output

pkg/logger's init()-configured global logrus logger, plus package
functions taking a hand-written function-name string at every call
site, is replaced with a plain logger.New() *slog.Logger constructor.
The returned *slog.Logger is threaded explicitly through every
function that logs (GetCloudflareAccessTokenForApp, StartMultipleProxies,
newDirector, ProxyService/ProxyCFAccess, cmd.Run/initConfig), created
once in cmd.Run's RunE.

LOG_LEVEL and LOG_FORMAT keep controlling level and format exactly as
before, including the fallback to info with a warning on an invalid
LOG_LEVEL. The one visible behavior change is that the unused trace
level goes away (nothing in production code called logger.Trace, and
slog has no built-in trace level).

Drops the github.com/sirupsen/logrus dependency entirely.
logrus's manual "function" field, hand-typed at each call site, went
away in the slog migration with nothing replacing it. slog's built-in
AddSource option gives the same "where did this happen" signal
automatically from the runtime call stack — always accurate, never
hand-typed or left stale after a rename.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant