Migrate logging from stdlib log to log/slog#92
Open
weppos wants to merge 6 commits into
Open
Conversation
Replace stdlib log with log/slog. Introduce a self-contained internal/logging package with New / ParseLevel, context helpers, a BugsnagLogger adapter (kept for workspace template parity even though strillone does not use Bugsnag), and an Err helper returning slog.Attr keyed on "error". config.init() calls slog.SetDefault once. Every call site uses slog.Info / slog.Error. cmd/main refactored to run() error shape. LOG_LEVEL accepts "debug |info|warn|error".
This repo does not use github.com/bugsnag/bugsnag-go, so the internal/logging.BugsnagLogger adapter was dead code carried forward from the workspace template during the zerolog → slog migration.
Rename HTTP request logging keys to a canonical http_-prefixed set for consistency across the workspace: - request_url / url -> http_url - request_method / method -> http_method - user_agent -> http_user_agent (kept where already named so) - forwarded_for -> http_forwarded_for - ip -> client_ip - scheme -> http_scheme - request_time -> duration_ms Only touches existing call sites — no new fields are introduced.
Go idiom prefers explicit bootstrap in main() over init() side effects: tests don't carry the import-time setup burden, the execution sequence is visible, and log output is fully consistent from the first line. Matches the pattern already used in go-remote-control-internal and nomad-deployer.
Wraps slog.SetDefault(logging.New(logging.ParseLevel(os.Getenv("LOG_LEVEL"))))
into a single call and emits a "Logger initialized" log line so the active
level is visible at startup. Each main() now starts with:
logging.SetupDefault()
replacing the longer boilerplate and restoring the init-time confirmation
log that was lost when setup moved out of config.init().
Config loading was moved out of config.init() into main(), so tests that depend on config.Config must load it themselves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces stdlib
logwith the stdliblog/slogstructured logger. Follows the template established by https://github.com/dnsimple/dnsimple-notifier/pull/443.This PR:
internal/loggingwith a bridge to use slog, and helpers likelogging.Errlog.Print*/log.Fatalwithslog.Info/slog.Error; request data moves into structured attrs (http_method,http_url,event_id)config.init()callsslog.SetDefaultonce;cmd/mainusesrun() errorLOG_LEVELacceptsdebug|info|warn|errorhttp_*prefix (http_method,http_url,http_user_agent,http_referer,http_scheme,http_forwarded_for,client_ip,duration_ms); only existing logged fields were renamed, no new ones addedLog output uses slog JSON defaults:
time(RFC 3339 nanoseconds),msg, uppercaselevel, plus asourcegroup fromAddSource: true. Error key is"error"vialogging.Err.Belongs to https://github.com/dnsimple/dnsimple-engineering/issues/286
📋 Deployment Pre/Post tasks
timefieldlevelfieldmsgfieldhttp_*keys to DD's canonical@http.*facets if APM correlation or the User-Agent parser is desired