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 Drain
s that offload processing to another
thread. Typically, serialization and IO operations are slow enough that
they make logging hinder the performance of the main code. Sending log
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 the documentation and implementation for more details.
It’s relatively easy to implement your 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 important to notice that destructors will not be called. This matters
for slog_async
as it prevents flushing of the async drain and
discards messages that are not yet written.
A way around this issue is encapsulate the construction of the logger into
its 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 |
|
AsyncCore | Core of |
AsyncCoreBuilder |
|
AsyncGuard | Async guard |
Enums
AsyncError | Errors reported by |
OverflowStrategy | Behavior used when the channel is full. |
Type Definitions
AsyncResult |
|