Struct lunatic_log::subscriber::fmt::FmtSubscriber
source · 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
impl FmtSubscriber
sourcepub fn new(level_filter: LevelFilter) -> Self
pub fn new(level_filter: LevelFilter) -> Self
Creates an instance of FmtSubscriber
.
Examples found in repository?
More 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));
}
sourcepub fn pretty(self) -> Self
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));
}
sourcepub fn with_color(self, color: bool) -> Self
pub fn with_color(self, color: bool) -> Self
Enables printing color.
sourcepub fn with_level(self, level: bool) -> Self
pub fn with_level(self, level: bool) -> Self
Print the log level.
sourcepub fn with_line_number(self, line_number: bool) -> Self
pub fn with_line_number(self, line_number: bool) -> Self
Print the line number where log originated.
sourcepub fn with_target(self, target: bool) -> Self
pub fn with_target(self, target: bool) -> Self
Print the target of the log.
sourcepub fn with_time_format(self, time_format: impl Into<String>) -> Self
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
impl Default for FmtSubscriber
source§impl<'de> Deserialize<'de> for FmtSubscriber
impl<'de> Deserialize<'de> for FmtSubscriber
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl Serialize for FmtSubscriber
Auto Trait Implementations§
impl RefUnwindSafe for FmtSubscriber
impl Send for FmtSubscriber
impl Sync for FmtSubscriber
impl Unpin for FmtSubscriber
impl UnwindSafe for FmtSubscriber
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more