xlogger (datamagix.xlogger) is a lightweight logging helper built on top of structlog with ANSI-coloured console output via colorama, JSON file sinks, and indentation helpers.
What it provides
- Colourised human-readable console output via a custom
_ColourRenderer. - Plain non-ANSI renderer for file sinks (
_PlainRenderer) and a mirroring processor so file sinks receive a copy of events. - Simple global API via the
Loggerclass:Logger.configure(...),Logger.get(name),Logger.add_file_sink(...),Logger.indent()/Logger.push()/Logger.pop(). - Optional JSON lines output for structured logs.
Dependencies
pyproject.toml:
Copying into another repo
API reference
Logger.configure
json=True emits JSONRenderer for console output.
Logger.get
name is provided it is bound as module and used for module colouring.
Logger.add_file_sink
level into the file. use_json=True writes JSON lines; otherwise uses a plain renderer.
Logger.remove_file_sink
Indentation helpers
contextvars.ContextVar, so it is task-local and works correctly with async code.
Other
Examples
Notes
colorama.init(autoreset=True)is called in the module to make colours work reliably on Windows.Logger.configure()callslogging.basicConfig(force=True), which replaces existing root handlers. Configure once, early.- File sinks are attached to the root
logginglogger, so third-party libraries that emit standard logging records are also written to the sink.
