[][src]Struct spirit_log::background::Background

pub struct Background { /* fields omitted */ }

A Transformation to move loggers into background threads.

By default, loggers created by the Pipeline are synchronous ‒ they block to do their IO. This puts the IO into a separate thread, with a buffer in between, allowing the rest of the application not to block.

The same warnings about lost messages and flushing as in the AsyncLogger case apply here. However, the Extensible::keep_guard and spirit::Extensible::autojoin_bg_thread can be used with the FlushGuard to ensure this happens automatically (the FlushGuard also implements Extension, which takes care of the setup).

Examples

use log::info;
use serde::Deserialize;
use spirit::prelude::*;
use spirit_log::{Background, Cfg as LogCfg, FlushGuard, OverflowMode};

#[derive(Clone, Debug, Default, Deserialize)]
struct Cfg {
    #[serde(flatten)]
    log: LogCfg,
}

impl Cfg {
    fn log(&self) -> LogCfg {
        self.log.clone()
    }
}

fn main() {
    Spirit::<Empty, Cfg>::new()
        .with(
            Pipeline::new("logging")
                .extract_cfg(Cfg::log)
                .transform(Background::new(100, OverflowMode::Block)),
        )
        .with_singleton(FlushGuard)
        .run(|_spirit| {
            info!("Hello world");
            Ok(())
        });
}

Methods

impl Background[src]

pub fn new(buffer: usize, mode: OverflowMode) -> Self[src]

Creates a new Background object.

Params

  • buffer: How many messages fit into the channel to the background thread.
  • mode: What to do if the current message does not fit.

Trait Implementations

impl PartialEq<Background> for Background[src]

impl Ord for Background[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl Clone for Background[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Eq for Background[src]

impl Copy for Background[src]

impl PartialOrd<Background> for Background[src]

impl Hash for Background[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl Debug for Background[src]

impl<I, F> Transformation<Dispatch, I, F> for Background[src]

type OutputResource = (LevelFilter, Box<dyn Log>)

The type of resource after the transformation.

type OutputInstaller = I

The type of installer after the transformation. Read more

Auto Trait Implementations

impl Send for Background

impl Sync for Background

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> IntoResult for T[src]

impl<T> Erased for T