[][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::{Empty, Pipeline, Spirit};
use spirit::prelude::*;
use spirit_log::{Background, Cfg as LogCfg, FlushGuard, OverflowMode};

#[derive(Clone, Debug, Default, Deserialize)]
struct Cfg {
    #[serde(default, skip_serializing_if = "LogCfg::is_empty")]
    logging: LogCfg,
}

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

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

Implementations

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 Clone for Background[src]

impl Copy for Background[src]

impl Debug for Background[src]

impl Eq for Background[src]

impl Hash for Background[src]

impl Ord for Background[src]

impl PartialEq<Background> for Background[src]

impl PartialOrd<Background> for Background[src]

impl StructuralEq for Background[src]

impl StructuralPartialEq 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 RefUnwindSafe for Background

impl Send for Background

impl Sync for Background

impl Unpin for Background

impl UnwindSafe for Background

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

impl<T> IntoResult<T> for T[src]

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.