Skip to main content

logwarden

Tests for your logs. logwarden checks the logs your services actually write against one logging standard, built on OpenTelemetry semantic conventions. It fails CI on a bad line the way a test fails on a bug, so logs stay searchable, safe and useful when something breaks.

PyPI Python CI License

uvx logwarden check logs.jsonl      # any language: it reads JSON lines, a file or stdin

Why

Logs get written by many people, in many services, and then mostly read during an incident. Code review rarely catches a bad log line, because reviewers see the code, not what it writes. So the same problems turn up in almost every codebase:

  • Every service names things differently. It's status, statusCode, http_status or response.code, so a query or a dashboard works for one service and silently misses the others.
  • Event names hold data. "Loaded 3 models" and "Loaded 4 models" are different events, so you can't count them, alert on them or group by them.
  • Errors don't say what failed. upstream_call_failed with no exception type, error type or status code means reproducing the bug just to read its cause.
  • Secrets and personal data leak. A password field, a JWT, an API key or a customer's email ends up in the log store, where far more people can read it.
  • Logs can't be joined with traces and metrics, because their field names don't match the ones OpenTelemetry uses everywhere else.

logwarden makes these problems fail the build. It checks output, not code, so it sees what your logging setup, middleware and third-party libraries really produce, in any language.

What a check looks like

This line looks normal:

{"timestamp":"2026-11-14T10:00:00Z","level":"info","event":"Loaded 3 models","logger":"x","status":200,"http_route":"/a","service.name":"yallmp","deployment.environment.name":"dev"}

logwarden finds five problems in it, each with the fix:

$ logwarden check logs.jsonl
  1	adr_banned_synonym - Banned synonym for an OTel semconv field
	fix: Rename the field to the semconv name given in the message.
	e.g. §2: 'status' is a banned synonym; use http.response.status_code

  1	adr_event_name - Event is a constant snake_case name
	fix: Use a fixed name like import_completed and move variable data into fields: log.info("import_completed", rows_imported=n).
	e.g. §4: event 'Loaded 3 models' must be a constant snake_case name

  1	adr_semconv_prefix - Semconv name written with underscores
	e.g. §2: 'http_route' uses '_' where semconv uses '.'; probably 'http.route'
  ...

The fixed line, which passes:

{"timestamp":"2026-11-14T10:00:00Z","level":"info","event":"models_loaded","logger":"app.models","http.response.status_code":200,"http.route":"/a","service.name":"yallmp","service.version":"0.1.0","deployment.environment.name":"development"}

The exit code is 0 when the logs pass, 1 when they have violations and 2 on a usage error, so CI, scripts and AI agents can rely on it.

What you get

  • One vocabulary across services. Field names come from the OpenTelemetry semantic conventions, the same names your traces and metrics use. Queries, dashboards and alerts written once work for every service.
  • Every failure can be diagnosed from its log line. Error lines must say what failed, and logwarden can check that each upstream's failure path is exercised by a test.
  • No secrets in the log store. Secret field names and value patterns (JWTs, API keys, credentials in URLs, emails, card numbers) fail the check. The Python setup redacts them before they're written.
  • Adoption without a big bang. A baseline records today's findings, so CI fails only on new ones while you fix the old ones.
  • Compliance you can measure. Every result is broken down by service, and production logs exported from Kibana or Elasticsearch can be checked the same way as test logs.
  • Reviewable changes to logging. A PR comment shows the new and fixed findings compared with the base branch, and which event names a change adds or removes.
  • AI agents that log well. A Claude Code plugin, an MCP server and an AGENTS.md section teach coding agents the standard and let them check their own work.

Use cases

1. Gate pull requests in CI

Run the tests with log capture, then let the GitHub Action check the logs. On a pull request it compares the run with the base branch, posts one comment that it updates on each push, and uploads an HTML report.

permissions:
  contents: read
  pull-requests: write          # only for comment: "true"
steps:
  - run: LOGWARDEN_CAPTURE=logs.jsonl pytest
  - uses: Ingeniator/logwarden@v0.8.0
    with:
      logs: logs.jsonl
      comment: "true"

With sarif: "true" (and security-events: write), GitHub code scanning shows each finding on the source line that logged it, right in the PR diff. Python's configure() and the Go recipe add the call-site fields that make this work.

GitLab and other CI systems run the same CLI with --snapshot, --compare, --markdown and --html; see docs/integration.md.

2. Adopt it on an existing service

logwarden baseline logs.jsonl       # record today's findings in .logwarden-baseline.json
logwarden check logs.jsonl          # from now on, fail only on new findings

Domain fields with no semconv name go in logwarden-fields.yaml. A rule you can't follow yet can be disabled in config, but only with a written reason.

3. Any language, any stack

logwarden checks output, so the language doesn't matter.

logwarden capture -o logs.jsonl -- npm test    # receive OTLP logs from any OTel SDK while the command runs
docker run --rm -v "$PWD:/work" ghcr.io/ingeniator/logwarden:0.8.0 check logs.jsonl   # no Python needed

There are setup recipes, with example output that passes, for Node (pino), Go (slog) and Java (logback).

4. Make good logs the default in Python

One call sets up structlog and the standard library so that every line passes: required service fields, trace context, exceptions as semconv fields, redaction and quiet noisy libraries.

from logwarden.logging import configure          # pip install 'logwarden[structlog]'
log = configure(service_name="billing-api", service_version="1.4.2", environment="production")
log.info("invoice_sent", **{"invoice.id": inv.id})

The pytest plugin captures logs from any test run (LOGWARDEN_CAPTURE=logs.jsonl pytest), and logwarden.testing provides assert_failure_logged and assert_logs_clean for asserting on logs in tests.

5. Review what a change does to the logs

logwarden check logs.jsonl --snapshot base.json          # on main
logwarden check logs.jsonl --compare base.json --html report.html   # on a branch: new and fixed
logwarden catalog logs.jsonl -o logwarden-events.toml    # the events a service emits, to commit

With an event catalog configured, check reports any event that isn't in it, so dashboards and alerts that match on event names don't break without anyone noticing.

6. Catch problems before anything runs

logwarden lint-code src/

This runs logwarden's Semgrep rules for Python, JavaScript/TypeScript, Go and Java: formatted event names, secret and banned field names, and print instead of the logger. --sarif writes the findings for code scanning, and a pre-commit hook (logwarden-lint-code) runs it on staged files. Ruff (LOG, G, TRY400) and sloglint cover more in an existing lint setup; the recommended config is in docs/integration.md §6.

7. Audit production logs from Kibana

Tests only cover the paths they run. Export a day of production logs from Kibana or Elasticsearch and check what services really write, broken down by service:

logwarden check export.csv --message-field log --ignore-field kubernetes --html report.html
logwarden check export.json --metrics metrics.prom     # per-service numbers for Prometheus

It reads Kibana CSV reports, Elasticsearch _search responses and NDJSON dumps, and unwraps records that Fluent Bit wrapped. See production logs.

8. Keep AI coding agents in line

  • Claude Code: /plugin marketplace add Ingeniator/logwarden, then /plugin install logwarden@logwarden. This adds a skill for writing good logs, the MCP server and /logwarden:check.
  • Other agents: logwarden init --agent adds a logwarden section to AGENTS.md. The MCP server (uvx --from 'logwarden[mcp]' logwarden mcp) provides check_logs, explain_rule, list_rules and get_standard.
  • Machine output: logwarden check --json gives each finding's line, rule and fix hint.

Quick start

uv add --dev logwarden                      # or: pipx install logwarden / uvx logwarden
logwarden init --agent                      # fields file + AGENTS.md section
LOGWARDEN_CAPTURE=logs.jsonl pytest         # capture logs (pytest plugin, auto-registered)
logwarden check logs.jsonl                  # check them

Project settings go in [tool.logwarden] in pyproject.toml, or in logwarden.toml. docs/integration.md covers capturing logs from any stack, project-only fields, the baseline, the event catalog and migrating a legacy service.

What it checks

Rule Fails on
adr_banned_synonym status=500 instead of http.response.status_code=500
adr_semconv_prefix http_route instead of http.route
missing_attribute a field that isn't semconv and isn't declared by the project
deprecated a renamed semconv field (gen_ai.system)
adr_missing_required no service.name, service.version or deployment.environment.name
adr_environment_value dev instead of development
adr_event_name event="Loaded 3 models" instead of models_loaded
adr_failure_context an error line without exception.type, error.type or a status code
adr_sensitive_data password=..., a JWT, an API key, user:pass@ in a URL, an email or card number
adr_non_json_line a plain-text line (a library banner, a printed traceback)
adr_trace_context a trace_id/span_id that isn't W3C lowercase hex
adr_upstream_failure_coverage an upstream in upstreams whose failure path no test exercised
adr_event_catalog an event missing from the event catalog, when events is configured

The standard, with the reasoning behind each rule, is in docs/standard.md. Each rule's failing and passing examples and its fix are in docs/rules.md.

How it compares

Checks When
Logger linters (Ruff LOG/G, sloglint) how the logger is called in source before running
Schema checks in the log pipeline records arriving in the log store in production, after the fact
logwarden the lines services really write, including their setup, middleware and libraries in tests and CI, before merge

These tools complement each other: logwarden's lint-code and its recommended Ruff and sloglint config cover the source side.

How it works

Each log line becomes a sample for OTel Weaver registry live-check. Weaver checks the field names against the semconv registry, plus logwarden's shared fields and the project's logwarden-fields.yaml, and runs logwarden's rules, written in Rego. Checks that span a whole run, such as upstream coverage and the event catalog, run in Python. logwarden capture turns OTLP log records into the same JSON lines first.

Requirements: Python 3.10+ on Linux, macOS or Windows, or the Docker image (linux/amd64 and linux/arm64), which works offline. Weaver and the semantic conventions are downloaded on first use, checked against pinned SHA-256 sums and cached. The core package has no dependencies besides tomli on Python 3.10.

Stability. Rule ids, the --json keys and exit codes are a public interface: they are only ever added to, never renamed. Every release has notes with a verification table, written before the work and filled in before the tag (CHANGELOG.md).

Roadmap

Next: a continuous check of the live log stream from Kafka and Fluent Bit, with Prometheus metrics and findings in Kibana. See docs/roadmap.md.

Contributing

Issues and pull requests are welcome. AGENTS.md describes the layout, the rules for adding a rule and the release process. It is written for humans and AI agents alike.

License

Apache-2.0

Metadata

Release files for logwarden 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for logwarden 0.8.0
File Size Uploaded Provenance Actions
logwarden-0.8.0.tar.gz 173.6 kB With provenance Details for logwarden-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for logwarden 0.8.0
File Interpreter ABI Platform Actions
logwarden-0.8.0-py3-none-any.whl Python 3 none any Details for logwarden-0.8.0-py3-none-any.whl

Total release size: 258.5 kB

Release files / logwarden-0.8.0.tar.gz

Download URL logwarden-0.8.0.tar.gz
Size 173.6 kB
Tags Source
SHA-256 checksum
How to use checksums
67aa5bf0d1efdab0e0af350af8391604e8b3ea68a607cdc9f365833be32fc671
BLAKE2b-256 checksum
How to use checksums
77dd41efb4b8b5609b07d5264ffb7de12641874e3597fd2569fd9f4a75aff7e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / logwarden-0.8.0-py3-none-any.whl

Download URL logwarden-0.8.0-py3-none-any.whl
Size 84.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da29292833018b4213d02069a82be9669bc9f8d6853f2037fb7c066538ae9ef6
BLAKE2b-256 checksum
How to use checksums
1043642f7d3e936029a5d3edf369df72dd96b1e87bda5b622aad198d432c41a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for logwarden 0.8.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for logwarden-0.8.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page