loguru

A drop-in replacement for Python's standard logging module that makes logging enjoyable, with almost no setup required.

Library
PyPI
v0.7.3
24,153 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
79 /100 Good
Development Activity 88
Maintenance 64
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
85 /100 Excellent
Architecture 85
Code Quality 88
Innovation 78
Learning Curve 90

Loguru replaces the boilerplate of Python’s built-in logging module with a single pre-configured object: from loguru import logger. Instead of wiring up handlers, formatters, and filters separately, one logger.add() call registers a sink — a file path, a stream, a function, or even a coroutine — with its own format, level, filter, colorization, and rotation/retention/compression behavior.

The library folds in features most teams otherwise hand-roll on top of stock logging: automatic file rotation and retention, brace-style string formatting, colorized terminal output, thread- and multiprocess-safe sinks via an optional queue, and an @logger.catch decorator that captures and fully renders exceptions — including local variable values in the traceback — even inside threads where standard logging silently drops them.

Under the hood, _logger.py implements the public Logger/Core classes while dedicated modules handle each concern in isolation: _handler.py manages per-sink dispatch and locking, _file_sink.py handles rotation/retention/compression policy, _colorizer.py and _better_exceptions.py handle terminal color markup and rich traceback rendering respectively, and _string_parsers.py parses human-readable size/time/frequency strings like “500 MB” or “12:00” into rotation rules.

What You Get

  • A single pre-configured logger object that writes to stderr out of the box — no boilerplate setup required to start logging
  • One add() function to register any sink (file path, stream, function, or coroutine) with its own format, level, filter, and color settings
  • Automatic file rotation, retention, and compression driven by simple strings like rotation="500 MB" or retention="10 days"
  • An @logger.catch decorator/context manager that captures exceptions — including those raised in threads — and renders full tracebacks with variable values
  • Thread-safe sinks by default, with an enqueue=True option for multiprocess-safe and async-safe logging via a background queue
  • Structured logging support: bind() and contextualize() attach contextual key/value data to log records, and serialize=True emits JSON

Common Use Cases

  • Adding production-ready logging to a script or small application without writing any handler/formatter boilerplate
  • Rotating and compressing log files automatically in a long-running service, replacing manual RotatingFileHandler configuration
  • Capturing and fully diagnosing exceptions raised inside worker threads or multiprocessing workers that standard logging would otherwise swallow
  • Emitting structured, JSON-serialized logs from a library or service for ingestion by a log aggregator
  • Adding contextual request/task IDs to log lines across an async or multi-threaded codebase via bind()/contextualize()

Under The Hood

Architecture

Loguru centers on a single pre-instantiated Logger object (loguru/__init__.py) backed by a shared Core that tracks the registered handlers, minimum level, and extra context. Each call to logger.add() constructs a Handler (_handler.py) wrapping a sink object — _simple_sinks.py defines StreamSink, StandardSink, and coroutine/queue-backed variants, while _file_sink.py layers rotation/retention/compression policy on top of file sinks. Formatting and colorization are handled by dedicated _colorizer.py and _better_exceptions.py modules rather than being embedded in the handler, and each Handler owns its own lock (_locks_machinery.py) so sinks are independently thread-safe; multiprocess/async safety is opt-in via an internal queue rather than a global default. This separation — one composable Handler/sink per add() call, coordinated through a shared Core — lets rotation, colorization, and exception rendering evolve independently without touching the public API surface.

Tech Stack

Loguru is pure Python (100% per GitHub’s language breakdown) with almost no runtime dependencies: colorama and win32-setctime are Windows-only extras declared with environment markers in pyproject.toml, and there is no dependency at all on Python’s own logging internals beyond an optional standard-library interception bridge (_simple_sinks.py’s StandardSink). The project builds with Flit (flit_core backend), supports Python 3.5 through 3.14 plus PyPy per its classifiers, and ships a py.typed marker with a separate __init__.pyi stub (kept apart from the implementation because type checkers can’t merge stubs with dynamically constructed objects like the module-level logger instance).

Code Quality

The tests/ directory contains over 50 targeted test modules (e.g. test_filesink_rotation.py, test_exceptions_catch.py, test_multiprocessing.py, test_coroutine_sink.py) run under pytest with pytest-cov for coverage and freezegun for deterministic datetime tests, plus a typesafety/ subdirectory for type-stub verification. Linting runs through Ruff with an extensive rule set (F, E, W, I, B, N, D, PT, PYI, RET, RUF) and numpydoc-style docstring conventions, Black for formatting, and Mypy pinned per Python version for type checking. CI (GitHub Actions) runs a dedicated tests.yml, lint.yml, docs.yml, and a CodeQL security scan on every push and PR, and the project is configured to treat warnings as test failures by default (filterwarnings = ['error']) with explicit, justified exceptions.

What Makes It Unique

Loguru’s core differentiator is collapsing standard logging’s Logger/Handler/Formatter/Filter object graph into a single logger.add() call per sink, removing the setup step that causes many Python projects to reach for print() instead of logging. Its exception handling goes further than typical logging libraries by rendering full tracebacks with the actual values of local variables at each frame (via a better_exceptions-derived renderer) and by correctly propagating exceptions raised inside threads, which standard logging does not surface at all. Human-readable rotation/retention strings ("500 MB", "12:00", "1 week") parsed by a dedicated string-parsing module, combined with built-in async/multiprocess-safe sinks via an opt-in queue, cover operational concerns that most other logging libraries leave to external configuration or third-party handlers.

Used by 21 apps in this directory

Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
Python
71%
MIT

Langflow

AI Agents · AI Development

155,973

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
64
Dependency
Built with
Python 71%
TypeScript 21%
Updated 6 days ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,055

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
68
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 2 months ago
TypeScript
56%
MIT

open-notebook

AI Assistants · Note Taking

40,513

A privacy-first, self-hosted AI research notebook with 18+ model providers, multi-speaker podcast generation, and full REST API—your open-source alternative to Google Notebook LM.

View details
89
Repo Health
84
Technical
71
Dependency
Built with
TypeScript 56%
Python 42%
Updated 1 weeks ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 6 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 6 days ago
Python
49%
Other

Arize Phoenix

Analytics · Devops · Monitoring

11,976

Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.

View details
92
Repo Health
88
Technical
67
Dependency
Built with
Python 49%
TypeScript 43%
Updated 6 days ago
TypeScript
48%
MIT

supermemory

AI Development · AI Memory · Note Taking

31,370

The state-of-the-art memory and context engine for AI agents — ranked #1 on all three major AI memory benchmarks.

View details
88
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 48%
MDX 32%
Python 17%
Updated 6 days ago
Python
68%
AGPL 3.0

Tracecat

AI Agents · Automation · Security

3,860

Open-source agentic security automation platform that runs AI agents and durable workflows at scale with sandboxed execution.

View details
89
Repo Health
88
Technical
66
Dependency
Built with
Python 68%
TypeScript 30%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers