Repository navigation
Add opt-in JSON structured logging (LOG_FORMAT=json) - #207
Merged
Merged
Conversation
Setting LOG_FORMAT=json makes mac-server write every log record (application, AUTH, library and HTTP access log) to stderr as one JSON object per line: timestamp (ISO 8601 with offset), level, logger, message, remote_addr/url from the Quart request context, exc_info and stack_info when present, filename/lineno/funcName in verbose mode, and any extra= fields (non-serializable values rendered with str()). Implementation is stdlib only: a JsonFormatter next to the existing RequestFormatter, and configure_log_format() called from main(). In JSON mode it leaves Quart's default_handler as the only root handler, because today the root logger has both the basicConfig handler and default_handler and every record is printed twice; reusing both would duplicate JSON lines or mix text into the stream. Text mode (the default) is untouched. Unknown LOG_FORMAT values keep text and log a warning rather than preventing startup. Docs: LOG_FORMAT in the configuration env var table plus a JSON Logging section with the field list; CLAUDE.md updated. Spec Kit artifacts in specs/20261121-083531-json-logging/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KQ8DrMX1VdrmZKGbKERH6h
There was a problem hiding this comment.
Claude Code review
From Claude, via the Claude PR Review workflow -- hence github-actions[bot].
Adds an opt-in LOG_FORMAT=json mode with a stdlib JsonFormatter and configure_log_format(), plus docs and tests. I found no high-signal bugs or CLAUDE.md violations. I read the diff directly and did not launch review subagents.
No issues found. Checked for bugs and CLAUDE.md compliance.
🔎 12s · 5 turns · $0.1150 · run log
Coverage Report
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Closes #52.
Summary
LOG_FORMATenv var:text(default, unchanged) orjson, case-insensitive. Unknown values keep text and log a warning instead of stopping startup.AUTH, library and HTTP access log) goes to stderr as one JSON object per line, with these fields:timestamp(ISO 8601 with offset),level,logger,messageremote_addrandurlfrom the Quart request context (nulloutside a request)exc_info/stack_infowhen presentfilename/lineno/funcNamein-vmodeextra=fields; values that can't be serialized are rendered withstr()JsonFormatterandconfigure_log_format()insrc/dm_mac/__init__.py, following the logging cookbook pattern linked in the issue. No new dependency.docs/source/configuration.rst, andCLAUDE.md.specs/20261121-083531-json-logging/.Pre-existing issue found (not changed here)
Today the root logger has two handlers, the
logging.basicConfig()one and Quart'sdefault_handler, so every text log line is printed twice (once without and once with[remote_addr]). This PR leaves text mode exactly as it is, to keep backward compatibility. JSON mode keeps onlydefault_handler, so each record appears once. Fixing the text-mode duplication would change existing output, so it's worth a separate issue.Verification
nox -s tests: 379 passed;src/dm_mac/__init__.pyat 100% coverage.nox -s pre-commitpasses.mypyshows no new errors in the changed files.GET /api/machinesand an authorizedPOST /api/machine/update:LOG_FORMAT=json: 18 of 18 stderr lines parse as JSON, no duplicates, andAUTHlines includeremote_addr/url.LOG_FORMAT=json -v: 69 of 69 lines parse and include the source location.* Serving Quart app ...) is printed to stdout rather than logged, so it is still plain text, the same as before.🤖 Generated with Claude Code
https://claude.ai/code/session_01KQ8DrMX1VdrmZKGbKERH6h