Features¶
Logust Features¶
Logust gives you the following:
Based on the loguru API¶
If you know loguru, you already know Logust.
- One global
logger, ready to use. NogetLogger(), no handler or formatter classes. logger.add()to add a sink,logger.remove()to remove it.bind(),contextualize(),patch(),opt(),catch(),level(),enable()/disable(),parse()...
For most code, migrating is changing the import:
Tip
There are some small differences. Check Migrate from loguru for the full list.
Fast, with a Rust core¶
The parts of logging that run for every message, formatting, JSON serialization and writing to files, are implemented in Rust.
Writing 10,000 messages to a file takes around 16 ms with Logust, versus around 960 ms with the standard logging and 2.7 s with loguru. See the Benchmarks.
On top of that, Logust only collects what your format needs. If your format doesn't show the caller ({name}, {function}, {line}...), Logust doesn't inspect the stack at all. More on that in Performance.
Beautiful by default¶
With zero configuration you get aligned output on standard error, as in loguru, with the time, level and caller of every message. Color is detected automatically, for the default handler and for the sinks you add, and NO_COLOR / FORCE_COLOR are respected.
You can also use color markup in your formats and messages, like <red>, <bold> or <level>. See Formatting.
Sinks: console, files, or anything¶
A sink is where your logs go. It can be:
sys.stdoutorsys.stderr.- A file path, as a
strorpathlib.Path. - Any Python callable, like a function or a method.
Each sink has its own level, format, filter, colors and options. See Handlers and Sinks.
Log files done right¶
All the things you need for files in production, as keyword arguments:
- Rotation by size (
"500 MB") or by time ("daily","1 hour"...). - Retention by age (
"30 days") or by number of files. - Compression of rotated files:
gz,bz2,zip,tar,tar.gz,tar.bz2. - Background writes with
enqueue=True, so logging doesn't block your code. mode,encodinganddelay, like the standardopen().
See Logging to Files and Rotation, Retention and Compression.
Structured logging¶
serialize=Truewrites one JSON object per line, ready for your log aggregator. See JSON Output.bind()attaches context to a logger, andcontextualize()attaches it to everything logged inside awithblock, safely across threads andasynciotasks. See Adding Context.- Keyword arguments to log calls also end up in the record's
extra.
Exceptions¶
logger.exception()logs the current exception with its full traceback.@logger.catch()logs any exception raised in a function or awithblock.backtraceanddiagnoseshow the values of the variables in each frame, per sink.
See Logging Exceptions and Traceback Detail.
Integrations¶
- Standard
logging: route everything, including third-party libraries, through Logust. See Intercept Standard Logging. - FastAPI and Starlette: request logging middleware with request IDs and sensitive data masking. See FastAPI and Starlette.
- Canonical events: one wide, structured event per request, with tail sampling. See Canonical Events.
- Progress bars: play nicely with
richandtqdm. See Progress Bars.
Ready for modern Python¶
- Python 3.10+, including Python 3.15.
- Fully typed, with type stubs for the Rust extension.
- Release automation builds wheels for free-threaded CPython (3.14t and 3.15t) on Linux, macOS, and Windows. See Threads and Processes.