pub struct FmtSubscriber { /* private fields */ }
Expand description

A subscriber printing to stdout/stderr.

Basic example

lunatic_log::init(FmtSubscriber::new(LevelFilter::Info));

Pretty example

lunatic_log::init(FmtSubscriber::new(LevelFilter::Info).pretty());

Implementations§

source§

impl FmtSubscriber

source

pub fn new(level_filter: LevelFilter) -> Self

Creates an instance of FmtSubscriber.

Examples found in repository?
examples/info.rs (line 5)
3
4
5
6
7
8
9
10
11
12
fn main() {
    // Initialize subscriber
    lunatic_log::init(FmtSubscriber::new(LevelFilter::Info));

    // Log message
    info!("Hello, {}", "World");

    // Wait for events to propagate
    lunatic::sleep(std::time::Duration::from_millis(50));
}
More examples
Hide additional examples
examples/pretty.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    // Initialize subscriber
    lunatic_log::init(FmtSubscriber::new(LevelFilter::Trace).pretty());

    // Log message
    error!("Error");
    warn!("Warn");
    info!("Info");
    debug!("Debug");
    trace!("Trace");

    // Wait for events to propagate
    lunatic::sleep(std::time::Duration::from_millis(50));
}
examples/multiple.rs (line 10)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
fn main() {
    // Setup multiple subscribers
    let subscriber = MultipleSubscribers::new()
        .add_subscriber(FmtSubscriber::new(LevelFilter::Info))
        .add_subscriber(FmtSubscriber::new(LevelFilter::Info));

    // Initialize multiple subscribers
    lunatic_log::init(subscriber);

    // Log message
    info!("Hello, {}", "World");

    // Wait for events to propagate
    lunatic::sleep(std::time::Duration::from_millis(50));
}
source

pub fn pretty(self) -> Self

Configures logging to be pretty with colors, filenames, and more.

Examples found in repository?
examples/pretty.rs (line 5)
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
    // Initialize subscriber
    lunatic_log::init(FmtSubscriber::new(LevelFilter::Trace).pretty());

    // Log message
    error!("Error");
    warn!("Warn");
    info!("Info");
    debug!("Debug");
    trace!("Trace");

    // Wait for events to propagate
    lunatic::sleep(std::time::Duration::from_millis(50));
}
source

pub fn with_color(self, color: bool) -> Self

Enables printing color.

source

pub fn with_file(self, file: bool) -> Self

Print filename where log originated.

source

pub fn with_level(self, level: bool) -> Self

Print the log level.

source

pub fn with_line_number(self, line_number: bool) -> Self

Print the line number where log originated.

source

pub fn with_target(self, target: bool) -> Self

Print the target of the log.

source

pub fn with_time(self, time: bool) -> Self

Print the time with the log.

source

pub fn with_time_format(self, time_format: impl Into<String>) -> Self

Customize the time format.

This must be in the strftime format supported by chrono.

Trait Implementations§

source§

impl Default for FmtSubscriber

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for FmtSubscriber

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Serialize for FmtSubscriber

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Subscriber for FmtSubscriber

source§

fn enabled(&self, metadata: &Metadata) -> bool

Indicate whether subscriber is enabled given some Metadata.
source§

fn event(&self, event: &Event)

Handle a log Event.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,