#ring-buffer #logging #logger #log #multi-threading #log-file

ring-log

High-performance logger with lock-free ring buffer

2 releases

0.1.1 Sep 23, 2024
0.1.0 Sep 7, 2024

#693 in Algorithms

Download history 185/week @ 2024-09-06 26/week @ 2024-09-13 161/week @ 2024-09-20 44/week @ 2024-09-27 10/week @ 2024-10-04 1/week @ 2024-10-11

219 downloads per month

MIT license

11KB
243 lines

build & test Crates.io license

fast-log

High-performance logger with lock-free ring buffer, use this library when you want to log in the hotpath and performance is critical.

Example

Submitting a log to either stdout or a file is very simple, you just give a closure which evaluates to a string. This is extremely fast, usually less than 100 nanos. A simple example:

let o = LoggerFileOptions {
    path: "log.txt",
    append_mode: false, // should the logger just append to what's already there or overwrite?
};

// The size is bounded, issuing a new log when the ringbuffer is full will block.
let logger = Logger::new(1024 * 8, Some(o));

// Log to stdout
logger.log(|| format!("To stdout: {}", 42));

// Log to the file, format_log! will prepend the file and LOC location to the log.
logger.log_f(|| format_log!("To log.txt {}", 5)); // path/to/file:LINE: To log.txt 5

// Blocks until all logs are handled.
logger.shutdown();

No runtime deps