Skip to main content

A high-performance, buffered, non-blocking logger for Python, implemented in Rust.

Project description

High-Performance Python Logger (in Rust)

PyPI version Downloads Py Versions

A high-performance, buffered, non-blocking logger for Python, with the core logic implemented in Rust for maximum speed and efficiency.

This logger is designed for high-throughput applications where standard Python logging would become a bottleneck. It sends logs on a dedicated background thread, ensuring your application's main threads are never blocked by I/O.

Features

  • Non-Blocking: Log calls return instantly.
  • Batching: Logs are sent to destinations in efficient batches (Elastic bulk API).
  • Resilient: In-memory buffer with retries for when destinations are temporarily unavailable.
  • Multiple Outputs: Configure logging to stdout, files, and Elasticsearch simultaneously.
  • Python logging Integration: Includes a logging.Handler to seamlessly integrate with the standard library.

Requirements

  • Python 3.9+
  • pip version 21 or newer.

This package uses modern Python packaging standards (PEP 517). Older versions of pip may not be able to install it correctly. You can upgrade pip with the following command:

pip install --upgrade pip

Pre-compiled wheels for officially Supported Platforms

  • Linux: x86_64 (manylinux compatible)
  • macOS: arm64 (Apple Silicon, Intel)
  • Windows: amd64

Installation

pip install py-hpl-logger

Quick Start

1(Optional). Configure your logger with ElasticConfig if needed:

ELASTIC_HOST=localhost
ELASTIC_PORT=9200
ELASTIC_USERNAME=elastic
ELASTIC_PASSWORD=changeme
ELASTIC_INDEX=my-python-logs

Configure using code:

elastic_config = ElasticConfig(
    host="localhost",
    port=9200,
    index="my-app",
    username="elastic",
    password="changeme"
)

Configure using .env. You can choose .env search depth using local_only argument:

elastic_config = ElasticConfig.from_env(local_only=False)
  1. Use the logger in your Python application:

    import logging
    from py_hpl_logger import LoggerBuilder, ElasticConfig, RustLogHandler
    
    # 1. Build the Rust logger backend once
    elastic_config = ElasticConfig(
        host="localhost",
        port=9200,
        index="my-app",
        username="elastic",
        password="changeme"
    )
    # default buffer params:
    # channel_size: 4096
    # batch_size: 256
    # `channel_size` sets maximum inner buffer size. If log amount exceeds this argument, over limiting logs are dropped to avoid memory leaks
    # `batch_size` is an argument used to bulk push amount of logs specified
    rust_backend = (
        LoggerBuilder()
        .with_stdout(True) # whether to use stdout or not
        .with_file_output("my_app_session")
        .with_elastic_output(elastic_config)
        .with_batch_size(1000) # how many log rows to wait before forced flush
        .with_flush_interval(1.0) # # how many seconds to wait before forced flush
        .build()
    )
    
    # 2. Integrate with Python's standard logging
    handler = RustLogHandler(rust_logger=rust_backend)
    formatter = logging.Formatter("%(threadName)s - %(message)s")
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    
    # 3. Use the standard logging API anywhere!
    log = logging.getLogger(__name__)
    log.info("This log is being handled by Rust!")
    log.error("This is a high-performance error log.")
    
    # 4. For graceful shutdown, flush the logger before exiting
    # (The logger also attempts to flush automatically on exit)
    rust_backend.flush()
    

Benchmark

Measurements completed under python3.11 on Apple M2 Max using remote Elastic Search instance with 2 Gb memory limit. The logger version used is py-hpl-logger==0.1.5.

20.000 messages were successfully written in a total time of 1.9494 seconds

    --- Running Benchmark for: High-Performance Rust Logger ---
    Logging 20,000 messages across 10 threads...
    Time taken for High-Performance Rust Logger: 0.1023 seconds

    Flushing Rust logger buffer...
    Flush took an additional 1.8471 seconds.

    --- Benchmark Results ---
    The application code was blocked for 0.1023 seconds with the Rust logger.
    Throughput: 195,474.04 logs/second
    Logs written: 20,000
    Time taken for flush: 1.8471 seconds
    Total time: 1.9494 seconds

Changelog

[0.1.5] - 2025-11-04

  • Added 'with_channel_size' constructor to LoggerBuilder

[0.1.6] - 2025-11-04

  • Added win_amd64 support
  • Added macos_x86_64 support
  • Added benchmark results

[0.1.9] - 2025-11-06

  • Added 'with_base_log' constructor to LoggerBuilder to add a base prefix '[<event.timestamp>] <event.level>:'
  • Fixed potential malloc problems in stdout buffer
  • Improved buffer offload with async elastic/file write execution

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py_hpl_logger-0.1.9-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded PyPymusllinux: musl 1.2+ x86-64

py_hpl_logger-0.1.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

py_hpl_logger-0.1.9-pp310-pypy310_pp73-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded PyPymusllinux: musl 1.2+ x86-64

py_hpl_logger-0.1.9-pp39-pypy39_pp73-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded PyPymusllinux: musl 1.2+ x86-64

py_hpl_logger-0.1.9-cp313-cp313t-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ x86-64

py_hpl_logger-0.1.9-cp39-abi3-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.9+Windows x86-64

py_hpl_logger-0.1.9-cp39-abi3-win32.whl (1.5 MB view details)

Uploaded CPython 3.9+Windows x86

py_hpl_logger-0.1.9-cp39-abi3-musllinux_1_2_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

py_hpl_logger-0.1.9-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

File details

Details for the file py_hpl_logger-0.1.9-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2ee7cb3c310d9deec7b3051b7f63ac6eccfd77273ab2c0d9fc76f0a871080f28
MD5 757e66cf73bfa6e7c255b445a48c4ca4
BLAKE2b-256 5feb481652a1363dd058c0d44cbf7920ca67d5c3de2c716b7708ef403847db32

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06a7c3bc63d35a89c75a27d07d3d21a5ec943bde451d5bf900387b46e93aa1f6
MD5 1444c032444f9de04517e47beead9507
BLAKE2b-256 579fc923edba4643ae653058c65af2c7e861b0635cf6dd11b59a60d2a453c36e

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-pp310-pypy310_pp73-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-pp310-pypy310_pp73-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9d929f90ff2366a498e454652aa4a336df60a6380e2313e97f688e6f873828ae
MD5 c86a75af0319556006ce3f121c40ec1f
BLAKE2b-256 7fa69f72c4bf94fb150f1c8af2a22267e6028ee69d60d0cd4fcd721e48e2d4ef

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-pp39-pypy39_pp73-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-pp39-pypy39_pp73-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dbede070371cd0cd050f6155d48da6b36dfae460e2a2291c72e4c06ebf8b66e5
MD5 0ec77a117c9edf9fa83881f983cd4338
BLAKE2b-256 a65f58e377238c21bc02f3d973f5dd9e94419a8516ba4870548e5aeaca1cff85

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-cp313-cp313t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ae096b1bd7024698959ec8270bb8fc93c7938c36130c6c54f4a05bdfde278e7b
MD5 c82e26f1982db4b7fecc25cf2ad8039b
BLAKE2b-256 1fe47372fe913981d8fd14361b21b978465c4a069145ac874393938960e0bdda

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1181870b5b0c8d97d82c572a612b46e3cd166e133554339c4c21d810bc8e28af
MD5 d269eb8513f59078ebfd712edf8ad600
BLAKE2b-256 eeeab1794352cf3464c0a1152c4787a3d9d8bd1bb0fbb462844338a9eaed679c

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-cp39-abi3-win32.whl.

File metadata

  • Download URL: py_hpl_logger-0.1.9-cp39-abi3-win32.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for py_hpl_logger-0.1.9-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 7cdb1335900b84897d579e8cbbdcb225e16a2e14cc002258b5aa6c6b96d67a7b
MD5 33f8a6218a96e55dcb03f617689d2bfd
BLAKE2b-256 254ff64af27ef2c29e55cf7f1d3b0331c9a6eef8dbd4c23604128a6fdde6faf8

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1eb686fc567d3fd2360ca9d2e570cb7838b402f904c749aef33bee57e1c66e50
MD5 9519e8cba825ad47207fce9a31bbb890
BLAKE2b-256 8ac6d53cc4cf19f3262445b852eca20cd8d15235eb759bb1c4d267d4568fbbc8

See more details on using hashes here.

File details

Details for the file py_hpl_logger-0.1.9-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for py_hpl_logger-0.1.9-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9a01e2385db9b16f660129deb863965ff16407ce796ca0c576e4b84f4b75927
MD5 2ad003d8e8eea803552bc7cde3667ab4
BLAKE2b-256 622be204b2b4d3ec603d8b513e89843e8361b49d73bef020f7fa3a5b6bc6e53f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page