API Reference

Loguru

Python logging made easy with a single global logger, sinks, and structured formatting.

Official Documentation ↗
CompatibilityThis documentation covers version v0.7. Check the official docs for the latest API surface.

Installation

pippip install loguru

Methods

Loguru aims to bring logging to the Python ecosystem with minimal setup. It provides a single global logger with a fluent API, structured context binding, file rotation, and beautiful default formatting.

Key Features

  • Zero config: One ready-to-use logger
  • Sinks: Files, streams, callables, and sockets
  • Rotation: By size, time, or age with retention
  • Binding: Per-request context via bind
  • Exceptions: catch decorator with tracebacks

Errors

The official API reference declares the following error types:

Security

Official security statements captured from the package documentation:

API reference evidence

Fetched from official sources on 2026-11-08T18:35:00+08:00 via WebFetch https://loguru.readthedocs.io/en/stable/api/logger.html;HTTP GET https://raw.githubusercontent.com/Delgan/loguru/master/loguru/_logger.py(本地提取签名).

FAQ

How is Loguru different from the stdlib logging module?
Loguru provides one preconfigured global logger, removing handler and formatter boilerplate. It adds structured binding, easy file rotation, and beautiful default output. You can still interop with stdlib via InterceptHandler.
How do I rotate log files?
Pass rotation to logger.add, e.g. rotation='10 MB' to rotate by size, rotation='12:00' by time, or rotation='1 week' by age. Combine with retention to delete old files and compression to zip them.
Can I use Loguru with multiple modules?
Yes. Import the same global logger everywhere. Use logger.bind(module=__name__) or logger.patch to add per-module context. The single logger keeps configuration centralized and consistent.