Skip to content

Loguru

A simple Python logging library that replaces print() debugging with ready-to-use logging.

Stars
24.2k
Forks
832
Licence
MIT
Language
Python
Last update
12 days ago
Type
Library

What it is

Loguru is a Python library for writing log messages from your code. It works out of the box with a single import, so you do not need to configure handlers or formatters first. It also adds features such as file rotation, retention, compression, colored output, and exception logging that the standard logging module makes more work to set up.

  • Replace print() calls in a script with leveled log messages sent to stderr
  • Write logs to a file that rotates at 500 MB and is compressed when closed
  • Wrap a function with the catch decorator so exceptions are logged instead of silently lost
  • Send colored, formatted logs to the terminal using markup tags in the format string

Great for

  • Python developers who want logging without much setup
  • Scripts that need quick, readable output to the terminal or a file
  • Developers who want log files to rotate or be cleaned up automatically
  • Projects that run code in threads or multiple processes and need logs that stay intact

Not ideal for

  • Projects that must stay on the standard library only, since Loguru is a third-party dependency
  • Teams that need a logging setup with fine control over every standard handler, because Loguru deliberately hides that layer
  • Non-Python projects, since the library is for Python code
Step-by-step guide: how to use LoguruInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Python (the README badge shows 3.5+ and PyPy support)

    Install from PyPI

    pip install loguru
  2. 2

    Run it

    • Install the package with pip install loguru
    • Add from loguru import logger to your script
    • Call logger.debug("message") or logger.info("message") to see output on stderr
    • Optionally call logger.add("file_{time}.log") to also write logs to a file
  3. 3

    Get the most out of it

    • Use logger.add with the level argument to filter which messages reach each sink
    • Use rotation, retention, and compression arguments on logger.add for long-running file logs
    • Use enqueue=True when logging from multiple processes
    • Use the @logger.catch decorator or context manager to log exceptions from threads and the main program
    • Use braces-style formatting such as logger.info("{} is the answer", 42) instead of % formatting

Downloads

Strengths

  • Works with one import: from loguru import logger
  • Adds file rotation, retention, and compression through simple arguments to add()
  • Has a large user base, with about 24,000 GitHub stars and an MIT license

Trade-offs

  • Per the README, sinks are not multiprocess-safe by default; you must enable enqueue to get that behavior
  • The README's benchmark claim about speed is struck through, so speed should not be assumed to be better than the built-in logging module
  • Uses its own logger object, so projects that already rely heavily on standard logging need to think about how the two interact (the README says it is compatible, but details are in the docs)

How it compares

ProjectStarsTypeLevelUpdatedBest for
loguru (this)24.2kLibrarybeginner12 days agoPython developers who want logging without much setup
monolog21.4kLibraryintermediate5 days agoPHP developers who need structured logs from an application
dozzle14.8kAppbeginner4 days agoDevelopers who want to watch container logs while debugging
logrus25.8kLibrarybeginner1 months agoGo developers with existing code that already uses Logrus
zap24.7kLibrarybeginner2 months agoGo developers building services that log heavily
pino18.3kLibrarybeginner1 months agoNode.js backend developers who want structured JSON logs

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.