pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
}Expand description
Severity level used for filtering log messages.
Levels are ordered from least to most severe:
Trace < Debug < Info < Warn < Error.
Variants§
Implementations§
Source§impl LogLevel
impl LogLevel
Sourcepub fn from_str(level_str: &str) -> LogLevel
pub fn from_str(level_str: &str) -> LogLevel
Converts a string into a LogLevel
Examples found in repository?
examples/instance.rs (line 10)
8fn main() -> Result<()> {
9 // Create an independent Logger instance (separate file/level) without using the global macros.
10 let logger = Logger::new("target/instance.log").with_level(LogLevel::from_str("Debug"));
11
12 // Non-fallible instance logging (write failures go to stderr).
13 logger.trace("This trace message will not be logged due to log level");
14 logger.debug("This debug message will not be logged due to log level");
15 logger.info("Instance logger ready");
16 logger.warn("This is a warning with the instance logger");
17 logger.error("An error occurred with the instance logger");
18
19 // Fallible instance logging: returns Result so you can handle failures.
20 logger.try_trace("This is a trace message with try")?;
21 logger.try_debug("This is a debug message with try")?;
22 logger.try_info("This is an info message with try")?;
23 logger.try_warn("This is a warning with try")?;
24 logger.try_error("An error occurred with try")?;
25
26 // Instance loggers don't have macros, so format messages manually (macros target the global logger).
27 logger.try_info(&format!(
28 "Logger initialized with path: {:?} and level: {:?}",
29 logger.path(),
30 logger.level()
31 ))?;
32
33 Ok(())
34}Trait Implementations§
Source§impl Ord for LogLevel
impl Ord for LogLevel
Source§impl PartialOrd for LogLevel
impl PartialOrd for LogLevel
impl Copy for LogLevel
impl Eq for LogLevel
impl StructuralPartialEq for LogLevel
Auto Trait Implementations§
impl Freeze for LogLevel
impl RefUnwindSafe for LogLevel
impl Send for LogLevel
impl Sync for LogLevel
impl Unpin for LogLevel
impl UnsafeUnpin for LogLevel
impl UnwindSafe for LogLevel
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