Skip to content

codechu/log-py

━━━━━━━━━━━━ 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.

PyPI Python CI License: MIT

codechu-log

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.

Install

pip install codechu-log

Python 3.10+. Built on stdlib logging; zero third-party deps.

Quick example

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"}

What you get

  • setup(name, *, level, file, json, max_bytes, backup_count, fmt, redact) — one-call configuration with RotatingFileHandler and a TTY-aware console handler.
  • Context(**fields)contextvars-backed scope; nested scopes merge, child wins on key conflict, propagation survives await.
  • 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.

Read more

Family

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.

Credits

  • Built on stdlib logging; contextvars pattern for async-safe context propagation.

License

MIT — see LICENSE.

Part of Codechu.

About

Structured logging — context propagation, JSON output, rotation, field redaction

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages