Repository navigation
Configure level, format and file from the environment - #53
Merged
Merged
Conversation
## Summary Deployments could not change logging behaviour without code changes. ## Changes - `setup_logging()` reads `LOG_LEVEL`, `LOG_FORMAT` (`pretty`, `compact`, `json` or `auto`) and `LOG_FILE` when the matching arguments are not passed. An explicit argument always wins. `LOG_FORMAT` is ignored once `mode` or `use_json` is passed. An unknown `LOG_FORMAT` raises `ValueError`. - To tell "not passed" from "passed the default", the defaults of `level`, `mode`, `use_json`, `to_file` and `file_path` become `None`. Behaviour without environment variables is unchanged, with one exception: `file_path=None` used to disable file output and now means "use the default", so use `to_file=False` for that. - README gains an environment variables section and updated options table, with tests for each variable, the overrides, and the error cases. ## Decision for review The issue suggests pretty output on a terminal and JSON otherwise as a default. Making that the default would silently change the output of every existing application that pipes its logs, so it is opt-in as `LOG_FORMAT=auto`. The default stays `pretty`. ## Verification - `pytest`: 123 passed (latest dependencies) and 103 passed with 20 skipped (no extras). `ruff` and `mypy --strict` are clean. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U2nYHVGDdthQpcwNBPbp8r
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
Deployments could not change logging behaviour without code changes.
Changes
setup_logging()readsLOG_LEVEL,LOG_FORMAT(pretty,compact,jsonorauto) andLOG_FILEwhen the matching arguments are not passed. An explicit argument always wins.LOG_FORMATis ignored oncemodeoruse_jsonis passed. An unknownLOG_FORMATraisesValueError.level,mode,use_json,to_fileandfile_pathbecomeNone. Behaviour without environment variables is unchanged, with one exception:file_path=Noneused to disable file output and now means "use the default", so useto_file=Falsefor that.Decision for review
The issue suggests pretty output on a terminal and JSON otherwise as a default. Making that the default would silently change the output of every existing application that pipes its logs, so it is opt-in as
LOG_FORMAT=auto. The default stayspretty.Verification
pytest: 123 passed (latest dependencies) and 103 passed with 20 skipped (no extras).ruffandmypy --strictare clean.Closes #22
🤖 Generated with Claude Code
https://claude.ai/code/session_01U2nYHVGDdthQpcwNBPbp8r
Generated by Claude Code