ring-log

Crates.ioring-log
lib.rsring-log
version0.2.15
created_at2024-09-07 21:58:00.15856+00
updated_at2025-01-03 05:58:45.080177+00
descriptionHigh-performance logger with lock-free ring buffer
homepage
repositoryhttps://github.com/freergit/ring-log.git
max_upload_size
id1367606
size13,832
sven (FreerGit)

documentation

README

build & test Crates.io license

ring-log

High-performance logger with lock-free ring buffer (SPSC), 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.
// When passing a LoggerFileOptions, .with_log_type(LogTo::File) is set implicitly.
let logger = Logger::builder(Some(o)).with_time(true);

// Log to file
logger.info(String::new);
logger.info(|| String::from("hello"));
logger.debug(|| "foo");

// Log to stdout, without date/time
let logger = logger.with_log_type(LogTo::Ephemeral).with_time(false);

// Will now log to stdout
logger.info(String::new);
logger.info(|| String::from("hello"));
logger.debug(|| "foo");

// Set it back to file 
let logger = logger.with_log_type(LogTo::File);

// Blocks until all logs are handled. Natural race condition if this is not called.
logger.shutdown();
Commit count: 0

cargo fmt