pub struct IcLogger { /* private fields */ }
Expand description
Implementations§
Source§impl IcLogger
impl IcLogger
Sourcepub fn new() -> IcLogger
pub fn new() -> IcLogger
Initializes the global logger with a IcLogger instance with
default log level set to Level::Warn
.
use ic_logger::IcLogger;
IcLogger::new().init().unwrap();
log::warn!("This is an example message.");
Examples found in repository?
More examples
Sourcepub fn with_level(self, level: LevelFilter) -> IcLogger
pub fn with_level(self, level: LevelFilter) -> IcLogger
Set the ‘default’ log level.
You can override the default level for specific modules and their sub-modules using with_module_level
Examples found in repository?
More examples
Sourcepub fn with_module_level(self, target: &str, level: LevelFilter) -> IcLogger
pub fn with_module_level(self, target: &str, level: LevelFilter) -> IcLogger
Override the log level for some specific modules.
This sets the log level of a specific module and all its sub-modules. When both the level for a parent module as well as a child module are set, the more specific value is taken. If the log level for the same module is specified twice, the resulting log level is implementation defined.
§Examples
Silence an overly verbose crate:
use ic_logger::IcLogger;
use log::LevelFilter;
IcLogger::new().with_module_level("chatty_dependency", LevelFilter::Warn).init().unwrap();
Disable logging for all dependencies:
use ic_logger::IcLogger;
use log::LevelFilter;
IcLogger::new()
.with_level(LevelFilter::Off)
.with_module_level("my_crate", LevelFilter::Info)
.init()
.unwrap();
Sourcepub fn init(self) -> Result<(), SetLoggerError>
pub fn init(self) -> Result<(), SetLoggerError>
‘Init’ the actual logger, instantiate it and configure it, this method MUST be called in order for the logger to be effective.