Repository navigation
R7: structured logging with zap - #231
Merged
Merged
Conversation
gogo v0.2.0 logs through zap, so L0 bumps it with the DefaultHandler call sites. Logs go to stdout: JSON by default, console in local development. Workers outside pkg/feedops, files that logged but no task owned, and the serve.go wiring are assigned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WyCPayWrFEFoujXXMsY1s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016WyCPayWrFEFoujXXMsY1s
Add pkg/logging: FromContext/WithLogger/With carry a *zap.Logger through a context or a *gin.Context (no-op when none is set), New builds it from --log-level and the new --log-format (json by default, console in local development), Middleware gives each request a logger with its request ID and logs the request, Recovery logs a panic with its stack. The router replaces gin.Default with gin.New plus these, adds the user ID once auth knows it, and logs through zap instead of the log package; serve builds the logger and the pprof server's fatal error goes through it. Bump gogo to v0.2.0, whose forms.DefaultHandler takes the request's logger. pkg/testutil/testlog records entries for tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
…til.LocalizeTime The feeds poller (L2) calls the feed cleaner (L1), so the signature between them is fixed before both run. util.LocalizeTime had no callers; pkg/util/date has the one in use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
dbsender takes WithLogger and its poller carries it in the context; the media server logs through the request's logger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
feeds and accounts take WithLogger for the feed poller and the login pruner, which carry it in their context; request code logs with logging.FromContext; the markdown transformers carry their own logger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
…the logger serve passes the logger to the mail sender, the feed poller and the login pruner. logging.WithLogger on a gin context also sets it on the request's context, so services called with c.Request.Context() log with the request's ID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
openDB logs a failure to close through the logger it is given: serve's, or for the other subcommands a console logger on stderr, apart from what they print on stdout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
…gent worktrees Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
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 the standard
logpackage,log/slogand log-likefmtcalls with one*zap.Logger, passed explicitly (no global logger).What changed
pkg/logging:FromContext/WithLogger/Withwork on a context, a*gin.Contextand itsc.Request.Context(), and return a no-op logger when none is set.Newbuilds the logger from--log-leveland the new--log-format:jsonis the default; compose and.env.examplesetconsole.Middlewaregives each request a logger with arequest_id, addsuser_idonce auth knows the user, and logs the request.Recoverylogs a panic with its stack.gin.New()plus that middleware, instead ofgin.Default().forms.DefaultHandlernow takes the request's logger.WithLoggeroption, wired inserve.go.logging.FromContext.servelog in the console format on stderr.logandlog/slogoutsidepkg/logging, tests included.pkg/testutil/testlogrecords log entries so tests can assert on them.util.LocalizeTimehad no callers and is deleted.Behavior is unchanged apart from the log output itself. A page that panics with
REPORT_PANICSon still answers 200, as it did before; that is filed as #230.Docs
docs/architecture.mdgains a "Logging" section;docs/testing.mdliststestlog.wave-runskill now says a signature shared by two parallel tasks is fixed before dispatch, and.claude/worktrees/is gitignored.docs/archive/history/r7.md.Checks
make check-qandmake cover-checkpass.make test-uifails only the three browser testsdocs/testing.mdalready lists as failing only there.🤖 Generated with Claude Code
https://claude.ai/code/session_012htHSQKmZ4rKeWkSPsJdgL
Generated by Claude Code