fastlogging-rs: High-Performance Logging for many different Programming Languages
DEV Community

fastlogging-rs: High-Performance Logging for many different Programming Languages

Overview

Every log.info(...) call can block your hot path, serialize your threads, and slow down your I/O-bound workloads. That's why I created fastlogging-rs: a Rust-powered logging framework that is extremely fast, thread-safe, and available with a similar API in 8 different programming languages.

Release 0.9.0 is available with the following features:

  • Initial release of the Rust core (fastlogging crate) with bindings for Python, C, C++, Go, Java (FFM and JNI), and C#
  • Non-blocking, asynchronous logging - writers run in background threads
  • Optional file rotation and compression
  • Optional AES encryption for network logging
  • Configuration via API or configuration file (JSON, XML, YAML)
  • Automatic forwarding of log messages from sub-processes to the main process
  • Logging to OpenTelemetry

Performance

Because speed matters…

Compared to Python's built-in logging module:

  • Writing to a file is up to 147× faster
  • Rotating file logging is up to 207× faster

Even compared to Apache Log4j, fastlogging-rs is up to 9× faster. When your application logs millions of messages, these speedups can turn minutes into seconds.

Language Bindings

fastlogging-rs is written in Rust and comes with thin wrappers for your favorite programming language. All bindings share a similar API, so you can use the same logging concepts across your whole stack:

  • Rust - fastlogging (native core)
  • Python - pyfastlogging (pyo3, >= 3.10)
  • C - cfastlogging (FFI, cbindgen header)
  • C++ - cxxfastlogging (type-safe cxx bridge)
  • C++ - cppfastlogging (C++17 RAII over the C ABI)
  • Go - gofastlogging (cgo wrapper)
  • Java - jfastlogging-ffm (Foreign Function & Memory API)
  • Java - jfastlogging-jni (Java Native Interface)
  • C# - csharpfastlogging (P/Invoke)

Architecture

Logging calls are non-blocking: each call performs a cheap level check (a single integer comparison, no lock) and hands the message to a channel. A background LoggingThread drains that channel and dispatches to each writer's own thread. The speed of your writers never slows down your application - as long as the queue doesn't run full.

Key architectural features:

  • Thread-safe logging calls
  • Multiple writers (sinks) per logger: console, file, network, syslog, callback
  • Optional file rotation and compression
  • Optional AES encryption for network logging
  • Configuration via API or configuration file (JSON, XML, YAML)
  • Automatic forwarding of log messages from sub-processes to the main process

Installation

Rust / Python

cargo add fastlogging
pip install pyfastlogging

Usage Example

Rust

use fastlogging::{logging_new_default, LoggingError};

fn main() -> Result<(), LoggingError> {
    let mut log = logging_new_default()?;
    log.info("Hello, fastlogging!")?;
    log.shutdown(false)?;
    Ok(())
}

Python

from fastlogging import Logging

log = Logging()
log.info("Hello, fastlogging!")
log.shutdown(False)

For more examples, see the GitHub repository.

Benchmarks

For detailed benchmark data and methodology, see the benchmark documentation. You can also explore the full benchmark results with interactive charts and tables: benchmarks.

Conclusion

If your application spends time logging, fastlogging-rs can provide substantial performance improvements with minimal code changes - in whichever language you happen to be writing. The API is intentionally familiar, making migration from logging, log4j, or your current framework straightforward while unlocking significantly faster execution.

Source code, documentation, and issue tracker: GitHub.

Licensed under the MIT or Apache-2.0 License.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.