[−][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::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]
fn eq(&self, other: &Background) -> bool
[src]
fn ne(&self, other: &Background) -> bool
[src]
impl Ord for Background
[src]
fn cmp(&self, other: &Background) -> Ordering
[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(&self) -> 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]
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 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,
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
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>), Error>
[src]
&mut self,
dispatch: Dispatch,
_fragment: &F,
_name: &'static str
) -> Result<(LevelFilter, Box<dyn Log>), Error>
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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.