Skip to content

muhammad-fiaz/logly

Repository files navigation

logly logo

PyPI PyPI - Downloads Documentation Supported Python GitHub stars GitHub issues GitHub pull requests GitHub last commit GitHub release codecov License Testing PyPI Publish Docs Deploy Supported Platforms Latest Release GitHub Sponsors

A Rust-powered, high-performance logging library for Python.

Documentation | API Reference | Quick Start | Contributing

A Rust-powered, high-performance logging library for Python with structured sinks, custom levels, rotation, compression, and telemetry integrations.

Note

This project is under active development. If you encounter any issues, bugs, or have feature requests, please open an issue on GitHub. Contributions are welcome!

If you love logly, make sure to give it a star!


Table of Contents (click to expand)

Features of Logly (click to expand)
Feature Description Documentation
Rust-native engine High-performance logging via PyO3 with zero unsafe Rust Docs
10 built-in levels TRACE, DEBUG, INFO, NOTICE, SUCCESS, WARNING, ERROR, FAIL, CRITICAL, FATAL Docs
Custom levels Define your own levels with custom priorities and colors Docs
Multiple sinks Console, file, callable, and network outputs simultaneously Docs
File rotation Size-based, time-based, clock-based, and weekday rotation Docs
Compression gzip, zip, bz2, xz, zstd with tar-compatible aliases Docs
JSON logging Structured JSON output for storage and analysis Docs
Context binding Attach persistent key-value pairs to logs Docs
Exception catching catch() decorator and context manager Docs
Background workers Non-blocking writes with enqueue=True Docs
40+ integrations FastAPI, Django, Flask, Rich, Redis, Kafka, and more Docs
Thread-safe Safe concurrent logging from multiple threads Docs
Source location Optional clickable file:line output Docs
Network logging HTTP, TCP, UDP, Syslog sinks Docs
Color themes Custom ANSI color themes per level Docs
Independent loggers Separate sink sets per logger instance Docs

Prerequisites

Requirement Version Notes
Python 3.10+ Download from python.org
Rust Latest stable Only needed for building from source
Operating System Linux, macOS, Windows Cross-platform support

Installation

Quick Install

pip install logly
# or
uv add logly

Tip

Install with optional extras for integrations: pip install "logly[rich,fastapi]"

All Optional Extras (42 integrations)
# Core
pip install logly                            # core only (no optional deps)

# Frameworks & Libraries
pip install "logly[rich]"                    # Rich console output
pip install "logly[fastapi]"                 # FastAPI middleware
pip install "logly[starlette]"               # Starlette middleware
pip install "logly[django]"                  # Django handler + middleware
pip install "logly[flask]"                   # Flask handler
pip install "logly[gunicorn]"                # Gunicorn worker hooks
pip install "logly[uvicorn]"                 # Uvicorn log config
pip install "logly[sqlalchemy]"              # SQLAlchemy query logging
pip install "logly[structlog]"               # Structlog processor
pip install "logly[celery]"                  # Celery task logging
pip install "logly[click]"                   # Click CLI output
pip install "logly[typer]"                   # Typer CLI output
pip install "logly[apscheduler]"             # APScheduler job logging
pip install "logly[rq]"                      # RQ worker logging
pip install "logly[pydantic]"                # Pydantic log handler
pip install "logly[tqdm]"                    # tqdm progress bar sink

# Monitoring & Observability
pip install "logly[opentelemetry]"           # OpenTelemetry export
pip install "logly[prometheus]"              # Prometheus metrics
pip install "logly[elasticsearch]"           # Elasticsearch indexing
pip install "logly[sentry]"                  # Sentry error tracking
pip install "logly[datadog]"                 # Datadog Logs API (stdlib)
pip install "logly[newrelic]"                # New Relic agent
pip install "logly[seq]"                     # Seq structured logs (stdlib)
pip install "logly[telemetry]"               # Generic telemetry (stdlib)

# Cloud Providers
pip install "logly[aws]"                     # AWS CloudWatch Logs
pip install "logly[gcloud]"                  # Google Cloud Logging
pip install "logly[azure]"                   # Azure Monitor

# Data Stores
pip install "logly[redis]"                   # Redis lists/streams
pip install "logly[kafka]"                   # Kafka topics (requires librdkafka)
pip install "logly[mongodb]"                 # MongoDB collections
pip install "logly[postgresql]"              # PostgreSQL tables
pip install "logly[rabbitmq]"                # RabbitMQ queues

# Log Aggregation
pip install "logly[logstash]"                # Logstash TCP/UDP (stdlib)
pip install "logly[graylog]"                 # Graylog GELF (stdlib)
pip install "logly[loki]"                    # Grafana Loki

# Notifications
pip install "logly[discord]"                 # Discord webhooks (stdlib)
pip install "logly[slack]"                   # Slack webhooks (stdlib)
pip install "logly[email]"                   # Email via SMTP (stdlib)
pip install "logly[http]"                    # HTTP endpoint (stdlib)

# Utilities
pip install "logly[compression]"             # Zstandard compression

# Everything
pip install "logly[all]"                     # all of the above

[!NOTE] Several integrations (datadog, seq, logstash, graylog, discord, slack, email, http, telemetry) use only Python stdlib and require no extra dependencies.

[!WARNING] The kafka extra requires librdkafka to be installed on your system. See Kafka integration docs for details.

uv Install Commands
# Core
uv add logly

# Frameworks & Libraries
uv add "logly[rich]"
uv add "logly[fastapi]"
uv add "logly[starlette]"
uv add "logly[django]"
uv add "logly[flask]"
uv add "logly[gunicorn]"
uv add "logly[uvicorn]"
uv add "logly[sqlalchemy]"
uv add "logly[structlog]"
uv add "logly[celery]"
uv add "logly[click]"
uv add "logly[typer]"
uv add "logly[apscheduler]"
uv add "logly[rq]"
uv add "logly[pydantic]"
uv add "logly[tqdm]"

# Monitoring & Observability
uv add "logly[opentelemetry]"
uv add "logly[prometheus]"
uv add "logly[elasticsearch]"
uv add "logly[sentry]"
uv add "logly[datadog]"
uv add "logly[newrelic]"
uv add "logly[seq]"
uv add "logly[telemetry]"

# Cloud Providers
uv add "logly[aws]"
uv add "logly[gcloud]"
uv add "logly[azure]"

# Data Stores
uv add "logly[redis]"
uv add "logly[kafka]"
uv add "logly[mongodb]"
uv add "logly[postgresql]"
uv add "logly[rabbitmq]"

# Log Aggregation
uv add "logly[logstash]"
uv add "logly[graylog]"
uv add "logly[loki]"

# Notifications
uv add "logly[discord]"
uv add "logly[slack]"
uv add "logly[email]"
uv add "logly[http]"

# Utilities
uv add "logly[compression]"

# Everything
uv add "logly[all]"

From Source

git clone https://github.com/muhammad-fiaz/logly.git
cd logly
uv sync
uv run maturin develop

Quick Start

from logly import logger

logger.trace("Detailed trace")
logger.debug("Debug info")
logger.info("Application started")
logger.notice("Notice message")
logger.success("Operation completed!")
logger.warning("Warning message")
logger.error("Error occurred")
logger.fail("Operation failed")
logger.critical("Critical system error!")
logger.fatal("Fatal system failure!")

logger.complete()

Custom Levels

from logly import logger

# Register a custom level with icon and color
logger.level("HTTP", no=21, color="blue", icon=">")
logger.level("DATABASE", no=22, color="magenta", icon="*")
logger.level("SECURITY", no=35, color="red", icon="!")

# Log with custom levels
logger.log("HTTP", "GET /api/users")
logger.log("DATABASE", "Connected to PostgreSQL")
logger.log("SECURITY", "Authentication failed")

# Use icon in format strings
sink_id = logger.add(
    lambda msg: print(msg, end=""),
    format="{level_icon} {level} | {message}",
    level="TRACE",
)
logger.log("HTTP", "GET /api/users")
logger.remove(sink_id)
# Output: > HTTP | GET /api/users

Usage Examples

File Logging

from logly import logger

logger.add(
    "logs/app.log",
    level="INFO",
    rotation="daily",
    retention="30 days",
    compression="gzip",
)

logger.info("Application started")
logger.complete()

Context Binding

from logly import logger

user_logger = logger.bind(user_id="12345", request_id="abc-789")
user_logger.info("User logged in")
# Output includes: user_id=12345 request_id=abc-789

Exception Catching

from logly import logger

with logger.catch():
    risky_operation()

# With options
with logger.catch(exclude=ValueError, onerror=lambda e: print(f"Failed: {e}")):
    dangerous_call()

Multiple Sinks

from logly import logger

logger.add("app.log", level="DEBUG", rotation="daily")
logger.add("errors.log", level="ERROR", retention="90 days")
logger.add("stdout", level="INFO", colorize=True)

logger.info("All three sinks receive this")

Independent Loggers

Use Logger() when a subsystem needs a separate set of sinks that does not write to the global logger.

from logly import Logger

api_logger = Logger()
worker_logger = Logger()

api_logger.add("api.log", level="INFO")
worker_logger.add("worker.log", level="DEBUG")

api_logger.info("request accepted")
worker_logger.debug("job claimed")

Lazy Evaluation

from logly import logger

logger.opt(lazy=True).debug("Result: {}", lambda: expensive_computation())

For more examples, see the documentation.


Log Levels

Level Priority Method Use Case
TRACE 5 logger.trace() Very detailed debugging
DEBUG 10 logger.debug() Debugging information
INFO 20 logger.info() General information
NOTICE 25 logger.notice() Notice messages
SUCCESS 30 logger.success() Successful operations
WARNING 40 logger.warning() Warning messages
ERROR 50 logger.error() Error conditions
FAIL 55 logger.fail() Operation failures
CRITICAL 60 logger.critical() Critical system errors
FATAL 70 logger.fatal() Fatal system errors

Architecture

Logly is built as a modular Rust workspace with a thin PyO3 binding:

Crate Purpose
error Error types and conversions
config Configuration data structures
levels Log level definitions and registry
record Log record builder
color ANSI color engine and themes
format Template, JSON, and custom formatters
filter Level, prefix, extra, and chain filters
rotate File rotation policies and execution
compress Compression codecs (gzip, zip, bz2, xz, zstd)
concurrency Background workers and thread pool
schedule Scheduled tasks and scheduler
context Bound context, scoped context, patchers
sink Sink trait and built-in implementations
core Logger engine dispatch
network HTTP, TCP, UDP, Syslog sinks
source Caller frame inspection

Building from Source

Tool Version Purpose
Rust Latest stable Compile the native engine
Python 3.10+ Runtime and build scripts
uv Latest Package manager (recommended)
Maturin 1.x Build backend for PyO3 wheels
# Install uv (if not already installed)
pip install uv

# Build the extension in development mode
uv run maturin develop

# Run Python tests
uv run pytest

# Run Rust tests
cargo test --workspace

# Lint
uv run ruff check .
cargo clippy --workspace --all-targets -- -D warnings

Documentation

Full documentation is available at: https://muhammad-fiaz.github.io/logly


Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Acknowledgements

Logly's Python API syntax and ergonomics are inspired by Loguru. The underlying engine is an independent, from-scratch Rust implementation.


License

This project is licensed under the MIT License.


Links