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
pip
pip install loguruMethods
No methods match this filter.
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:
ValueError(add() 的 Raises 段(官方 API 文档)) — official text: “ValueError – If any of the arguments passed to configure the sink is invalid.” (source: https://loguru.readthedocs.io/en/stable/api/logger.html, fetched 2026-11-08T18:35:00+08:00)
Security
Official security statements captured from the package documentation:
- 官方要求生产环境关闭 diagnose,避免异常追踪泄露敏感数据 — “This should be set to
Falsein production to avoid leaking sensitive data.” (source: https://loguru.readthedocs.io/en/stable/api/logger.html, fetched 2026-11-08T18:35:00+08:00)
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(本地提取签名).
logger→ signature from https://raw.githubusercontent.com/Delgan/loguru/master/loguru/_logger.py; official text: “def log(__self, __level, __message, *args, **kwargs): # noqa: N805 r”““Logmessage.format(*args, **kwargs)with severitylevel.”logger.add→ signature from https://loguru.readthedocs.io/en/stable/api/logger.html; official text: “add(sink, *, level=‘DEBUG’, format=‘{time:YYYY-MM-DD HH:mm:ss.SSS} |{level: <8} |{name} :{function} :{line} -{message} ’, *filte”logger.bind→ signature from https://raw.githubusercontent.com/Delgan/loguru/master/loguru/_logger.py; official text: “def bind(__self, **kwargs): # noqa: N805 “”“Bind attributes to theextradict of each logged message record.”logger.catch→ signature from https://raw.githubusercontent.com/Delgan/loguru/master/loguru/_logger.py; official text: “def catch( self, exception=Exception, *, level=“ERROR”, reraise=False, onerror=None, exclude=None, default=None, message=“An error has been caught in function ‘{record[function]}’, “ “process ‘{record[process].name}’ ({r”logger.configure→ signature from https://raw.githubusercontent.com/Delgan/loguru/master/loguru/_logger.py; official text: “def configure(self, *, handlers=None, levels=None, extra=None, patcher=None, activation=None): “”“Configure the core logger.”
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.
Report a problem with this API docOpens a pre-filled issue on GitHub.