pub struct LoggerBuilder { /* private fields */ }Expand description
Constructs an nice-log logger.
Implementations§
Source§impl LoggerBuilder
impl LoggerBuilder
Sourcepub fn new(max_log_level: LevelFilter) -> Self
pub fn new(max_log_level: LevelFilter) -> Self
Create a builder for a logger. The logger can be installed using the
build_global() function.
Examples found in repository?
More examples
examples/basic.rs (line 6)
3fn main() {
4 // The log output is determined by the `NICE_LOG` environment variable as dedicated by the rules
5 // outlined in the repository's readme
6 nice_log::LoggerBuilder::new(LevelFilter::Trace)
7 .build_global()
8 // In this example something would be have gone very wrong if we cannot set up the logger.
9 // If there however is a possibility that the logger is configured multiple times then this
10 // error should be handled appropriately.
11 .expect("A logger has already been set up");
12
13 // When changing some of the level filter above some of these messages may no longer be printed
14 log::error!("This is an error");
15 log::warn!("This is a warning");
16 log::info!("This is a regular log message");
17 log::debug!("This is a debug message, usually only made visible during debug builds");
18 log::trace!("This is a trace message, usually hidden unless explicitly opted into");
19
20 // Debug and trace messages contain the module path
21 some_module::log_from_module();
22}Sourcepub fn build_global(self) -> Result<(), SetLoggerError>
pub fn build_global(self) -> Result<(), SetLoggerError>
Install the configured logger as the global logger. The global logger can only be set once.
Examples found in repository?
More examples
examples/basic.rs (line 7)
3fn main() {
4 // The log output is determined by the `NICE_LOG` environment variable as dedicated by the rules
5 // outlined in the repository's readme
6 nice_log::LoggerBuilder::new(LevelFilter::Trace)
7 .build_global()
8 // In this example something would be have gone very wrong if we cannot set up the logger.
9 // If there however is a possibility that the logger is configured multiple times then this
10 // error should be handled appropriately.
11 .expect("A logger has already been set up");
12
13 // When changing some of the level filter above some of these messages may no longer be printed
14 log::error!("This is an error");
15 log::warn!("This is a warning");
16 log::info!("This is a regular log message");
17 log::debug!("This is a debug message, usually only made visible during debug builds");
18 log::trace!("This is a trace message, usually hidden unless explicitly opted into");
19
20 // Debug and trace messages contain the module path
21 some_module::log_from_module();
22}Sourcepub fn always_show_module_path(self) -> Self
pub fn always_show_module_path(self) -> Self
Always show the module path. Normally this is only shown for the messages on the Debug
level or on higher verbosity levels. Useful for debugging.
Sourcepub fn filter_crate(self, crate_name: impl Into<String>) -> Self
pub fn filter_crate(self, crate_name: impl Into<String>) -> Self
Filter out log messages produced by the given crate.
Sourcepub fn filter_module(self, crate_name: impl Into<String>) -> Self
pub fn filter_module(self, crate_name: impl Into<String>) -> Self
Filter out log messages produced by the given module. Module names are matched exactly and case sensitively. Filtering based on a module prefix is currently not supported.
Sourcepub fn with_output_target(
self,
target: OutputTarget,
) -> Result<Self, SetTargetError>
pub fn with_output_target( self, target: OutputTarget, ) -> Result<Self, SetTargetError>
Explicitly set the output target for the logger. This is normally set using the NICE_LOG
environment variable. Returns an error if the target could not be set.
Trait Implementations§
Source§impl Debug for LoggerBuilder
impl Debug for LoggerBuilder
Source§impl From<SetTargetError> for LoggerBuilder
impl From<SetTargetError> for LoggerBuilder
Source§fn from(value: SetTargetError) -> Self
fn from(value: SetTargetError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for LoggerBuilder
impl RefUnwindSafe for LoggerBuilder
impl Send for LoggerBuilder
impl Sync for LoggerBuilder
impl Unpin for LoggerBuilder
impl UnsafeUnpin for LoggerBuilder
impl UnwindSafe for LoggerBuilder
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