# Loguru: Python Logging Made Simple and Enjoyable

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/delgan-loguru
Generated for open source discovery and AI-assisted research.

Loguru is a powerful and user-friendly Python library designed to simplify logging. It aims to make logging an enjoyable and straightforward process, eliminating the need for complex configurations. With Loguru, developers can implement robust logging solutions with minimal boilerplate, enhancing debugging and application monitoring.

GitHub: https://github.com/Delgan/loguru
OSRepos URL: https://osrepos.com/repo/delgan-loguru

## Summary

Loguru is a powerful and user-friendly Python library designed to simplify logging. It aims to make logging an enjoyable and straightforward process, eliminating the need for complex configurations. With Loguru, developers can implement robust logging solutions with minimal boilerplate, enhancing debugging and application monitoring.

## Topics

- python
- logging
- loguru
- logger
- development
- utility
- open-source

## Repository Information

Last analyzed by OSRepos: Wed Dec 10 2025 12:00:57 GMT+0000 (Western European Standard Time)
Detail views: 1
GitHub clicks: 1

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction

Loguru is a Python library that revolutionizes the way developers approach logging. It addresses the common pain points of traditional logging setups, offering a solution that is both simple to use and incredibly powerful. Designed to be ready out-of-the-box, Loguru encourages developers to integrate logging from the very beginning of their projects, making debugging and monitoring significantly easier. It provides a unified, intuitive API, replacing complex configurations with a single `logger` object and an `add()` function.

## Installation

Getting started with Loguru is straightforward. You can install it using pip:

bash
pip install loguru


## Examples

Loguru simplifies many common logging tasks with elegant solutions.

### Basic Usage

Start logging instantly without any configuration:

python
from loguru import logger

logger.debug("That's it, beautiful and simple logging!")


### File Logging with Rotation and Retention

Easily log to files, with built-in support for rotation, retention, and compression:

python
logger.add("file_1.log", rotation="500 MB")    # Automatically rotate too big file
logger.add("file_2.log", rotation="1 week")    # New file is created each day at noon
logger.add("file_X.log", retention="10 days")  # Cleanup after some time
logger.add("file_Y.log", compression="zip")    # Save some loved space


### Pretty Logging with Colors

Loguru automatically adds colors to your terminal output, enhancing readability. You can customize the style using markup tags:

python
import sys
logger.add(sys.stdout, colorize=True, format="<green>{time}</green> <level>{message}</level>")
logger.info("This message will be <level>colorful</level>!")


### Robust Exception Catching

Ensure all exceptions are caught and logged, even in threads, using the `catch()` decorator or context manager:

python
from loguru import logger

@logger.catch
def my_function(x, y, z):
    # An error? It's caught anyway!
    return 1 / (x + y + z)

my_function(1, 2, -3)


## Why Use Loguru?

Loguru stands out for several compelling reasons:

*   **Simplicity**: Eliminates boilerplate code and complex configurations, making logging accessible from the start.
*   **Rich Features**: Offers advanced functionalities like automatic file rotation, retention, compression, modern string formatting, and asynchronous logging.
*   **Enhanced Debugging**: Provides fully descriptive exceptions with stack traces and variable values, significantly speeding up bug identification.
*   **Developer Experience**: Features like colored output, customizable levels, and seamless integration with standard logging make the development process more pleasant.
*   **Thread and Multiprocess Safety**: Ensures log integrity in complex applications.
*   **Structured Logging**: Supports serialization to JSON and contextual binding for easier log analysis.

## Links

*   **GitHub Repository**: [https://github.com/Delgan/loguru](https://github.com/Delgan/loguru){target="_blank"}
*   **Official Documentation**: [https://loguru.readthedocs.io/en/stable/index.html](https://loguru.readthedocs.io/en/stable/index.html){target="_blank"}
*   **API Reference**: [https://loguru.readthedocs.io/en/stable/api/logger.html](https://loguru.readthedocs.io/en/stable/api/logger.html){target="_blank"}