Crate slog_async [] [src]

Async drain for slog-rs

slog-rs is an ecosystem of reusable components for structured, extensible, composable logging for Rust.

slog-async allows building Drains that offload processing to another thread. Typically serialization and IO operations can be slow enough that they could make logging hinder performance of the main code. Sending logging records to another thread is much faster (ballpark of 100ns).

Note: Unlike other logging solutions slog-rs does not have a hardcoded async logging implementation. This crate is just a reasonable reference implementation. It should have good performance and work well in most use cases. See documentation and implementation for more details.

It's relatively easy to implement own slog-rs async logging. Feel free to use this one as a starting point.

Beware of std::process::exit

When using std::process::exit to terminate a process with an exit code it is imporant to notice that destructors will not be called. This matters for slog_async as it will prevents flushing of the async drain and discarding messages that are not yet written.

A way around this issue is encapsulate the construction of the logger into it's own function that returns before std::process::exit is called.

// ...
fn main() {
    let _exit_code = run(); // logger gets flushed as `run()` returns.
    // std::process::exit(exit_code) // this needs to be commented or it'll
                                     // end the doctest
}

fn run() -> i32 {
   // initialize the logger

   // ... do your thing ...

   1 // exit code to return
}

Structs

Async

Async drain

AsyncBuilder

Async builder

AsyncCore

Core of Async drain

AsyncCoreBuilder

AsyncCore builder

AsyncGuard

Async guard

Enums

AsyncError

Errors reported by Async

Type Definitions

AsyncResult

AsyncResult alias