pub struct AsyncPoolSink { /* private fields */ }
multi-thread
only.Expand description
A combined sink, logging and flushing asynchronously (thread-pool-based).
Expensive operations (such as log
and flush
) on asynchronous sinks will
be performed asynchronously on other threads.
Since there is no waiting, errors that occur while performing asynchronous operations will not be returned to the upper level, and instead the error handler of the sink will be called.
Users should only use asynchronous combined sinks to wrap actual sinks that require a long time for operations (e.g., file sinks that are frequently flushed, sinks involving networks), otherwise they will not get a performance boost or even worse.
Since the thread pool has a capacity limit, the queue may be full in some cases. When users encounter this situation, they have the following options:
-
Adjust to a larger capacity via
ThreadPoolBuilder::capacity
. -
Adjust the overflow policy via
AsyncPoolSinkBuilder::overflow_policy
. -
Set up an error handler on asynchronous combined sinks via
AsyncPoolSinkBuilder::error_handler
. The handler will be called when a record is dropped or an operation has failed.
§Note
Errors that occur in log
and flush
will not be returned directly,
instead the error handler will be called.
§Examples
See ./examples directory.
Implementations§
Source§impl AsyncPoolSink
impl AsyncPoolSink
Sourcepub fn builder() -> AsyncPoolSinkBuilder
pub fn builder() -> AsyncPoolSinkBuilder
Constructs a builder of AsyncPoolSink
with default parameters:
Parameter | Default Value |
---|---|
level_filter | All |
error_handler | default error handler |
overflow_policy | Block |
thread_pool | internal shared default thread pool |
Sourcepub fn sinks(&self) -> &[Arc<dyn Sink>]
pub fn sinks(&self) -> &[Arc<dyn Sink>]
Gets a reference to internal sinks in the combined sink.
Sourcepub fn set_error_handler(&self, handler: Option<ErrorHandler>)
pub fn set_error_handler(&self, handler: Option<ErrorHandler>)
Sets a error handler.
Trait Implementations§
Source§impl Sink for AsyncPoolSink
impl Sink for AsyncPoolSink
Source§fn set_formatter(&self, formatter: Box<dyn Formatter>)
fn set_formatter(&self, formatter: Box<dyn Formatter>)
For AsyncPoolSink
, the function performs the same call to all
internal sinks.