AsyncPoolSink

Struct AsyncPoolSink 

Source
pub struct AsyncPoolSink { /* private fields */ }
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:

§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

Source

pub fn builder() -> AsyncPoolSinkBuilder

Available on crate feature multi-thread only.

Constructs a builder of AsyncPoolSink with default parameters:

Examples found in repository?
examples/07-async.rs (line 13)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9    let path = env::current_exe()?.with_file_name("async.log");
10    let file_sink = FileSink::builder().path(path).build_arc()?;
11
12    // AsyncPoolSink is a combined sink which wraps other sinks
13    let async_pool_sink = AsyncPoolSink::builder().sink(file_sink).build_arc()?;
14
15    let async_logger = Logger::builder()
16        .sink(async_pool_sink)
17        .flush_level_filter(LevelFilter::All)
18        .build_arc()?;
19
20    info!(logger: async_logger, "Hello, async!");
21
22    Ok(())
23}
Source

pub fn sinks(&self) -> &[Arc<dyn Sink>]

Available on crate feature multi-thread only.

Gets a reference to internal sinks in the combined sink.

Trait Implementations§

Source§

impl Sink for AsyncPoolSink

Available on crate feature multi-thread only.
Source§

fn log(&self, record: &Record<'_>) -> Result<()>

Logs a record.
Source§

fn flush(&self) -> Result<()>

Flushes any buffered records.
Source§

fn flush_on_exit(&self) -> Result<()>

Flushes any buffered records at program exit. Read more
Source§

fn should_log(&self, level: Level) -> bool

Determines if a log message with the specified level would be logged.
Source§

impl SinkPropAccess for AsyncPoolSink

Available on crate feature multi-thread only.
Source§

fn set_formatter(&self, formatter: Box<dyn Formatter>)

For AsyncPoolSink, the function performs the same call to all internal sinks.

Source§

fn level_filter(&self) -> LevelFilter

Gets the log level filter.
Source§

fn set_level_filter(&self, level_filter: LevelFilter)

Sets the log level filter.
Source§

fn set_error_handler(&self, handler: ErrorHandler)

Sets a error handler. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.