low_latency_log

Crates.iolow_latency_log
lib.rslow_latency_log
version0.2.0
sourcesrc
created_at2024-06-20 09:01:15.0244
updated_at2024-06-20 09:30:52.753836
descriptionFast and Low Latency Logging Library for Rust
homepage
repositoryhttps://github.com/WANG-lp/low-latency-log
max_upload_size
id1277758
size50,551
Lipeng (William) Wang (WANG-lp)

documentation

README

Fast and Low Latency Logging Library for Rust

Introduction

low-latency-log is a high-performance and low-latency Rust logging library.

Features

  • Very Low Latency: low-latency-log is designed with performance in mind, utilizing techniques such as minimizing the size of critical data structures, avoiding locks on critical paths, and caching formatted strings.
  • Async Logging: low-latency-log offloads all heavy logging operations (such as formatting, time conversion, etc.) to independent threads, ensuring the calling thread is not blocked.

Benchmark

low-latency-log offers comparable p999 latency to quill and leads in throughput among quill, spdlog-rs, ftlog, and fast_log.

For more details, please refer to the Benchmark.

To build the benchmark binaries, run:

cargo b -r -p bench

Usage example

use low_latency_log::{info, Level};
use std::fs;

fn main() {
    let rc = RollingCondition::new().daily();
    // Remember to keep the following guard, otherwise the global logger stops immediately when the guard auto-drops
    let _guard = low_latency_log::Logger::new(rc, "/dev/shm".to_string(), "log.log".to_string())
        .cpu(1)
        .init()
        .unwrap();

    for i in 1..1_000_001 {
        info!("number {}", i);
    }

    // _guard auto-dropped and log flushed
}

TODOs

The following optimizations are in progress:

  • Optimize std format!.
  • Improve ufmt to provide more types of formatting support (e.g., floating-point types).
  • Support custom format types, as currently low_latency_log outputs fixed time and log formats.
  • Optimize performance when using the log crate.

low_latency_log is heavily inspired by the following projects

License

This project is licensed under the Apache License.

Some code comes from the logflume project. Please refer to LICENSE-LOGFLUME for more information.

Commit count: 22

cargo fmt