Skip to content

fix(serve): keep json_logging's startup debug line out of plain-text stderr - #37

Merged
vinismarques merged 2 commits into
mainfrom
fix/json-logging-startup-line
Oct 5, 2026
Merged

vinismarques merged 2 commits into
mainfrom
fix/json-logging-startup-line

Conversation

@vinismarques

Copy link
Copy Markdown
Member

Summary

With ENABLE_JSON_LOGGING=true, server startup wrote one plain-text line to stderr:

DEBUG:json_logging:Update all existing logger to using JSONLogFormatter

Log collectors that parse stderr as JSON (e.g. Google Cloud Logging) record any non-JSON stderr line as ERROR, so every start showed up as a spurious error.

import json_logging
  get_library_logger("json_logging")   # pins the library logger to DEBUG
logging.basicConfig(...)               # root handler: plain text on stderr
json_logging.init_fastapi(...)
  _logger.debug("Update all existing logger ...")   # → plain line via root
json_logging.config_root_logger()      # root handler switches to JSON, too late
 if settings.enable_json_logging:
     register_client_safe_request_extractor()
+    logging.getLogger("json_logging").setLevel(logging.INFO)
     json_logging.init_fastapi(enable_json=True)

Reordering basicConfig before the import doesn't fix this: the library always pins its logger to DEBUG on first import. Its WARNING and ERROR messages still get through.

Evidence

  • Before: test_json_logging_startup_writes_only_json (start the app in a fresh interpreter, assert every stdout/stderr line parses as JSON) fails:
    JSONDecodeError on 'DEBUG:json_logging:Update all existing logger to using JSONLogFormatter'
    After: passes. test_json_logging_keeps_reporting_its_own_warnings confirms a WARNING from the json_logging logger is still emitted as JSON.

Merge Danger

Door: two-way

Blast Radius: cosmetic

Only DEBUG records from the json_logging logger are dropped. Side effect: setting the library's own ENABLE_JSON_LOGGING_DEBUG no longer surfaces its DEBUG lines (its INFO and WARNING ones still appear).

Bumps the version to 5.2.1 for the release.

@vinismarques
vinismarques merged commit c9d58fe into main Oct 5, 2026
1 check passed
@vinismarques
vinismarques deleted the fix/json-logging-startup-line branch October 5, 2026 00:42
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