[−][src]Struct spirit_log::background::Background
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]
fn clone(&self) -> Background
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Background
[src]
impl Debug for Background
[src]
impl Eq for Background
[src]
impl Hash for Background
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Background
[src]
fn cmp(&self, other: &Background) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<Background> for Background
[src]
fn eq(&self, other: &Background) -> bool
[src]
fn ne(&self, other: &Background) -> bool
[src]
impl PartialOrd<Background> for Background
[src]
fn partial_cmp(&self, other: &Background) -> Option<Ordering>
[src]
fn lt(&self, other: &Background) -> bool
[src]
fn le(&self, other: &Background) -> bool
[src]
fn gt(&self, other: &Background) -> bool
[src]
fn ge(&self, other: &Background) -> bool
[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
fn installer(&mut self, original: I, _name: &'static str) -> I
[src]
fn transform(
&mut self,
dispatch: Dispatch,
_fragment: &F,
_name: &'static str
) -> Result<(LevelFilter, Box<dyn Log>), AnyError>
[src]
&mut self,
dispatch: Dispatch,
_fragment: &F,
_name: &'static str
) -> Result<(LevelFilter, Box<dyn Log>), AnyError>
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoResult<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
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>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,