Repository navigation
fix(serve): keep json_logging's startup debug line out of plain-text stderr - #37
Merged
Merged
Conversation
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.
Summary
With
ENABLE_JSON_LOGGING=true, server startup wrote one plain-text line to stderr: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.
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
basicConfigbefore 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
test_json_logging_startup_writes_only_json(start the app in a fresh interpreter, assert every stdout/stderr line parses as JSON) fails:JSONDecodeErroron'DEBUG:json_logging:Update all existing logger to using JSONLogFormatter'After: passes.
test_json_logging_keeps_reporting_its_own_warningsconfirms a WARNING from thejson_logginglogger is still emitted as JSON.Merge Danger
Door: two-way
Blast Radius: cosmetic
Only DEBUG records from the
json_logginglogger are dropped. Side effect: setting the library's ownENABLE_JSON_LOGGING_DEBUGno longer surfaces its DEBUG lines (its INFO and WARNING ones still appear).Bumps the version to 5.2.1 for the release.