Skip to content

logwarden v0.5.0

Status: Released 2026-11-18 · tag v0.5.0.

Make good logs the easy path: one call sets up logging that passes the standard, helpers make failure logs easy to write and to test, and the check can prove that every upstream's failure path was exercised.

What's new

  • logwarden.logging.configure() (install logwarden[structlog]). The reference structlog + stdlib setup from the standard, in one call:
from logwarden.logging import configure
log = configure(service_name="billing-api", service_version="1.4.2",
                environment="production")
  • Every line is one JSON object on stdout, including stdlib and third-party loggers. Third-party lines get the constant event library_log, with their text in log.record.original.
  • Adds timestamp (ISO-8601 UTC), level, logger, service.name, service.version, deployment.environment.name, and trace_id/span_id from the active OpenTelemetry span when the OTel API is installed.
  • Exceptions (exc_info=True, log.exception) become exception.type, exception.message and exception.stacktrace.
  • Redacts secrets: fields named like password/token/authorization, and tokens, API keys, credentials in URLs, emails and card numbers inside values. keep= exempts fields that must be logged.
  • Noise control: chatty loggers (urllib3, httpx, httpcore, botocore, …) at WARNING; health/metrics paths (/health, /healthz, /livez, /readyz, /ready, /metrics) dropped from access logs and from events with that http.route/url.path.
  • Arguments fall back to OTEL_SERVICE_NAME, SERVICE_VERSION, DEPLOYMENT_ENVIRONMENT and OTEL_RESOURCE_ATTRIBUTES. A missing name/version or an undocumented environment (dev, prod) raises ValueError at startup instead of producing bad logs.
  • json=False gives human-readable console output for local development.
  • Helpers for failure logs in logwarden.logging: extract_error_code(response), extract_error_message(response, limit=500) (OpenAI, Anthropic, FastAPI and generic {code, message} bodies, httpx/requests responses, dicts or text) and scrub(text, limit=500) (redaction + truncation).
  • Test helpers in logwarden.testing: capture() collects the JSON lines the service writes during a block, assert_failure_logged(records, event, **fields) checks a failure line exists and says what failed, and assert_logs_clean(records) runs the full logwarden check on them.
  • New rule adr_upstream_failure_coverage (§10). With upstreams = ["api.openai.com", ...] in the config, check fails when the run has no warning/error (or *_failed) line with server.address equal to an upstream, i.e. no test exercised that upstream's failure path. Findings for the whole run have line: null. (The roadmap said upstreams.yaml; a list in the existing config needs no YAML parser.)

Changes

  • adr_failure_context doesn't apply to library_log lines: a third-party library's warning can't be given failure context by the service. Its other rules still apply.
  • The standard's reference setup section now shows configure(); the hand-written processor list stays as the explanation.

Fixes

  • No git clone on every check. Weaver used to clone the OTel semantic-conventions repository from GitHub on every run. That made each check depend on the network and failed whenever the clone did ("Failed to consume the pack sent by the remote" broke the test run while v0.5.0 was being built). logwarden now downloads the pinned release archive once, checks its SHA-256, caches it next to Weaver (LOGWARDEN_CACHE), and points the registry at the local copy. After the first run, checks work offline. LOGWARDEN_SEMCONV points at a local semconv model directory instead.

Breaking changes

None. The core install still has no dependencies besides tomli on Python 3.10.

Upgrading from v0.4.0

uv add logwarden[structlog]==0.5.0           # runtime dependency now, for configure()

Replace the project's logging setup with configure(...), run uvicorn with log_config=None so it doesn't reinstall its own handlers, and list upstreams in [tool.logwarden] upstreams = [...]. CI: uses: Ingeniator/logwarden@v0.5.0. Claude Code: /plugin update logwarden@logwarden.

Verification

CI run 44258769971 (commit 7f661ff): 118 tests passed on each of ubuntu py3.10, ubuntu py3.13, macos py3.13 and windows py3.13; action, package and plugin jobs passed.

# Claim How it was checked Result
1 Logs from configure() pass the check test_claim1_configure_output_passes_check: a test app logs info, a warning with error.type, log.exception, contextvars, and a third-party logger at info/warning/error (with an exception), plus uvicorn access lines. All lines are JSON objects, and logwarden check reports 0 violations ✅
2 Redaction removes everything adr_sensitive_data flags test_claim2_redaction_leaves_nothing_for_the_rule: all 24 cases from the v0.4.0 sensitive-data tests logged through configure() → 0 adr_sensitive_data. test_claim2_keep: keep=["user.email"] keeps that field, and another email is still redacted ✅
3 Exceptions and trace context test_claim3_exceptions: exception.type/.message/.stacktrace set and exc_info removed, also for a third-party logger's exception. test_claim3_trace_context with the OTel SDK: no ids outside a span; inside a span 32/16-char ids that pass the check ✅
4 Noise control /health access line, the event with http.route="/metrics" and an httpx info line are dropped, while /v1/x is kept; urllib3, httpx, httpcore and botocore are at WARNING ✅
5 Config fallbacks and validation OTEL_SERVICE_NAME/SERVICE_VERSION/DEPLOYMENT_ENVIRONMENT and OTEL_RESOURCE_ATTRIBUTES fallbacks; ValueError for a missing version and for dev; a second configure() leaves exactly one logwarden handler; json=False gives console output ✅
6 Real service: switching to configure() removes the setup findings yallmp with setup_logging() replaced by configure() through a pytest plugin in the scratchpad (yallmp untouched): 433 tests pass, 573 lines. Violations drop from 2843 to 1122: adr_missing_required 1719 → 0, and one log.exception line now has exception.* instead of a text exception field (adr_banned_synonym 241 → 240, adr_failure_context 86 → 85). No new rule appears. The other changed lines differ only in values inside the message (a retry delay, a temp path) ✅
7 Error helpers test_claim7_*: OpenAI (code, and type when code is null), Anthropic, FastAPI detail string and list, generic {code, message}, an error string that is a code or a sentence, an HTML body; each as a dict and as a response object; real httpx.Response and requests.Response; an API key in the message is redacted; message capped at 500, scrub at its limit ✅
8 Test helpers test_claim8_*: capture() returns the 3 lines logged in the block; assert_failure_logged returns the record and fails with "no failure line logged for event='missing_failed'" or "doesn't say what failed"; assert_logs_clean passes on clean records and fails naming adr_event_name ✅
9 Upstream failure coverage test_upstreams.py: an uncovered host fails with line: null and run in the text output; a *_failed event covers a host; baseline (entry per host) and disable apply; a string, [1] or [""] → exit 2 ✅
10 Packaging CI package job: the core wheel venv has no structlog, and import logwarden.logging raises an error naming logwarden[structlog]; .whl[structlog] in a clean venv writes a JSON line ✅
11 Docs and rule wiring test_rules_wired.py passes with the new rule; standard (§10, reference setup), rules.md, integration.md, README, skill and AGENTS.md describe configure(), the helpers and upstreams ✅
12 CI green on Linux, macOS, Windows; release publishes CI above. Dry run: release run 44259009302 published 0.5.0.dev5 to TestPyPI; in a clean environment uvx --from 'logwarden[structlog]==0.5.0.dev5' wrote a line with configure() and uvx logwarden==0.5.0.dev5 check passed it (downloading semconv into an empty cache). Real publish: tag v0.5.0 → release run 44259490530 published 0.5.0 to PyPI and created the GitHub release. From PyPI in a clean environment with an empty cache: uvx --from 'logwarden[structlog]==0.5.0' writes a line with configure() that uvx logwarden==0.5.0 check passes; examples/bad.jsonl gives 10 violations; the MCP server serves all 4 tools ✅
13 No network after the first run test_semconv.py: with a warm cache and every proxy variable pointed at a closed port, check passes and downloads nothing; a corrupted archive fails the SHA-256 check and leaves nothing in the cache; an unpinned version and a bad LOGWARDEN_SEMCONV give clear errors; LOGWARDEN_SEMCONV is used with an empty cache. The suite went from about 200s to 41s locally ✅