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

pub struct Background { /* fields omitted */ }
Expand description

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

The type of resource after the transformation.

The type of installer after the transformation. Read more

Creates the installer. Read more

Transforms one instance of the resource. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Turns self into the result.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.