Skip to content

Configure level, format and file from the environment - #53

Merged
markbac merged 1 commit into
mainfrom
feat/22-env-config
Oct 3, 2026
Merged

markbac merged 1 commit into
mainfrom
feat/22-env-config

Conversation

@markbac

@markbac markbac commented Oct 3, 2026

Copy link
Copy Markdown
Owner

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.

Closes #22

🤖 Generated with Claude Code

https://claude.ai/code/session_01U2nYHVGDdthQpcwNBPbp8r


Generated by Claude Code

## 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
@markbac
markbac merged commit e3198ea into main Oct 3, 2026
9 checks passed
@markbac
markbac deleted the feat/22-env-config branch October 19, 2026 08:53
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.

Feature: environment-driven configuration (LOG_LEVEL, LOG_FORMAT, APP_ENV)

2 participants