━━━━━━━━━━━━ c o d e c h u · l o g ━━━━━━━━━━━━
2026-05-20T12:34:56.789Z INFO myapp started service=api user=onur
2026-05-20T12:34:57.013Z WARN myapp retrying attempt=2 backoff=0.5s
2026-05-20T12:34:57.812Z ERROR myapp failed err="ECONNRESET" req=r-42
━━━ one call. structured records. async-safe context. ━━━
Stdlib-only structured logging — JSON or text, rotating, redacting,
contextvars-aware.
Stdlib-only structured logging for Python. One call sets up a
rotating file handler, a TTY-aware console handler, optional JSON
output, and a redaction list. Context propagates through
contextvars so it survives await boundaries.
pip install codechu-logPython 3.10+. Built on stdlib logging; zero third-party deps.
from codechu_log import setup, bind, Context
log = bind(setup("myapp", file="app.log", json=True), service="api")
with Context(request_id="r-42"):
log.info("started", user="onur")Output (one JSON object per line):
{"ts": "2026-05-20T12:34:56.789012+00:00", "level": "INFO",
"logger": "myapp", "msg": "started",
"fields": {"service": "api", "request_id": "r-42", "user": "onur"},
"exc_info": null, "pid": 4321, "thread": "MainThread"}setup(name, *, level, file, json, max_bytes, backup_count, fmt, redact)— one-call configuration withRotatingFileHandlerand a TTY-aware console handler.Context(**fields)—contextvars-backed scope; nested scopes merge, child wins on key conflict, propagation survivesawait.bind(logger, **fields)— always-on fields per logger instance.structured(logger)—log.info("msg", key=value)lifts kwargs into the structured payload.redact=[…]— listed field keys are replaced with<redacted>in both text and JSON output.
- API reference — every public symbol and the JSON schema.
- Recipes — common configurations.
- Changelog
| Library | Purpose |
|---|---|
| codechu-events | Thread-safe multi-channel pub/sub bus |
| codechu-ipc | Local IPC — Unix socket, FIFO, JSON-line protocol |
| codechu-xdg | XDG Base Directory helpers, vendor-namespaced |
| codechu-fmt | Human-readable sizes, durations, rates |
| codechu-fs | Filesystem primitives — atomic write, XDG trash |
Full ecosystem: github.com/codechu.
- Built on stdlib
logging;contextvarspattern for async-safe context propagation.
MIT — see LICENSE.
Part of Codechu.