NopLogBuilder

Struct NopLogBuilder 

Source
pub struct NopLogBuilder {}
Expand description

A type to construct a basic RingLog which drops all log messages.

Implementations§

Source§

impl NopLogBuilder

Source

pub fn new() -> Self

Create a new log builder.

Examples found in repository?
examples/demo-multi.rs (line 38)
24fn main() {
25    let default = LogBuilder::new()
26        .output(Box::new(Stdout::new()))
27        .build()
28        .expect("failed to initialize default log");
29
30    let command = LogBuilder::new()
31        .output(Box::new(
32            File::new("command.log", "command.old", 100).expect("failed to create file log"),
33        ))
34        .format(klog_format)
35        .build()
36        .expect("failed to initialize command log");
37
38    let noplog = NopLogBuilder::new().build();
39
40    let mut drain = MultiLogBuilder::new()
41        .default(default)
42        .add_target("command", command)
43        .add_target("noplog", noplog)
44        .build()
45        .start();
46
47    std::thread::spawn(move || loop {
48        let _ = drain.flush();
49        std::thread::sleep(Duration::from_millis(100));
50    });
51
52    error!("error");
53    warn!("warning");
54    info!("info");
55    debug!("debug");
56    trace!("trace");
57
58    command!("\"get 0\" 0 0");
59
60    noplog!("this won't get displayed");
61
62    std::thread::sleep(Duration::from_millis(1000));
63}
Source

pub fn build(self) -> RingLog

Consumes the builder and returns an RingLog.

Examples found in repository?
examples/demo-multi.rs (line 38)
24fn main() {
25    let default = LogBuilder::new()
26        .output(Box::new(Stdout::new()))
27        .build()
28        .expect("failed to initialize default log");
29
30    let command = LogBuilder::new()
31        .output(Box::new(
32            File::new("command.log", "command.old", 100).expect("failed to create file log"),
33        ))
34        .format(klog_format)
35        .build()
36        .expect("failed to initialize command log");
37
38    let noplog = NopLogBuilder::new().build();
39
40    let mut drain = MultiLogBuilder::new()
41        .default(default)
42        .add_target("command", command)
43        .add_target("noplog", noplog)
44        .build()
45        .start();
46
47    std::thread::spawn(move || loop {
48        let _ = drain.flush();
49        std::thread::sleep(Duration::from_millis(100));
50    });
51
52    error!("error");
53    warn!("warning");
54    info!("info");
55    debug!("debug");
56    trace!("trace");
57
58    command!("\"get 0\" 0 0");
59
60    noplog!("this won't get displayed");
61
62    std::thread::sleep(Duration::from_millis(1000));
63}

Trait Implementations§

Source§

impl Default for NopLogBuilder

Source§

fn default() -> NopLogBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.