Skip to main content

AsyncDispatcher

Struct AsyncDispatcher 

Source
pub struct AsyncDispatcher { /* private fields */ }
Expand description

A dispatcher that offloads log processing to a background thread.

Implementations§

Source§

impl AsyncDispatcher

Source

pub fn new( dispatcher: Box<dyn Dispatcher + Send + Sync>, buffer_size: usize, ) -> Self

Creates a new AsyncDispatcher that wraps the provided dispatcher.

This constructor spawns a dedicated background thread that manages log dispatching. All log records sent to this dispatcher are queued in an internal bounded channel before being processed asynchronously.

§Arguments
  • dispatcher - The underlying Dispatcher responsible for the actual output (e.g., writing to a file or standard streams).
  • buffer_size - The maximum capacity of the internal channel. When the buffer is full, logging threads will block until space becomes available (backpressure).
§Panics

This method will panic if the operating system fails to spawn the background OS thread.

§Example
use cirious_codex_logger::{AsyncDispatcher, StdoutDispatcher, StyledTerminalFormatter};

let stdout_dispatcher = Box::new(StdoutDispatcher::new(StyledTerminalFormatter));
let async_dispatcher = AsyncDispatcher::new(stdout_dispatcher, 1024);
Examples found in repository?
examples/async_logging.rs (line 11)
9fn main() {
10  let stdout = Box::new(StdoutDispatcher::new(StyledTerminalFormatter));
11  let async_dispatcher = Box::new(AsyncDispatcher::new(stdout, 100));
12
13  init(async_dispatcher).ok();
14
15  warn!("This log is processed in a background thread without blocking.");
16}

Trait Implementations§

Source§

impl Debug for AsyncDispatcher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Dispatcher for AsyncDispatcher

Source§

fn dispatch(&self, record: &Record) -> DispatchResult

Dispatches a log record to the underlying destination. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.