Expand description
§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)
}
fn run() -> i32 {
// initialize the logger
// ... do your thing ...
1 // exit code to return
}
Structs§
- Async
- Async drain
- Async
Builder Async
builder- Async
Core - Core of
Async
drain - Async
Core Builder AsyncCore
builder- Async
Guard - Async guard
- Async
Record - Serialized record.
Enums§
- Async
Error - Errors reported by
Async
- Overflow
Strategy - Behavior used when the channel is full.
Type Aliases§
- Async
Result AsyncResult
alias