pub struct Logger { /* private fields */ }Expand description
Implementations§
Source§impl Logger
impl Logger
Sourcepub fn new() -> Logger
pub fn new() -> Logger
Initializes the global logger with a Logger instance with
default log level set to Level::Trace.
use lite_log::LiteLogger as Logger;
Logger::new().env().init().unwrap();
log::warn!("This is an example message.");Sourcepub fn from_env() -> Logger
👎Deprecated since 1.12.0: Use env instead. Will be removed in version 2.0.0.
pub fn from_env() -> Logger
env instead. Will be removed in version 2.0.0.Simulates env_logger behavior, which enables the user to choose log level by
setting a RUST_LOG environment variable. The RUST_LOG is not set or its value is not
recognized as one of the log levels, this function will use the Error level by default.
You may use the various builder-style methods on this type to configure
the logger, and you must call init in order to start logging messages.
use lite_log::LiteLogger as Logger;
Logger::from_env().init().unwrap();
log::warn!("This is an example message.");Sourcepub fn env(self) -> Logger
pub fn env(self) -> Logger
Simulates env_logger behavior, which enables the user to choose log
level by setting a RUST_LOG environment variable. This will use
the default level set by with_level if RUST_LOG is not set or
can’t be parsed as a standard log level.
This must be called after with_level. If called before
with_level, it will have no effect.
Sourcepub fn with_level(self, level: LevelFilter) -> Logger
pub fn with_level(self, level: LevelFilter) -> Logger
Set the ‘default’ log level.
You can override the default level for specific modules and their sub-modules using with_module_level
This must be called before env. If called after env, it will override the value loaded from the environment.
Sourcepub fn with_module_level(self, target: &str, level: LevelFilter) -> Logger
pub fn with_module_level(self, target: &str, level: LevelFilter) -> Logger
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 lite_log::Logger;
use log::LevelFilter;
Logger::new().with_module_level("chatty_dependency", LevelFilter::Warn).init().unwrap();Disable logging for all dependencies:
use lite_log::Logger;
use log::LevelFilter;
Logger::new()
.with_level(LevelFilter::Off)
.with_module_level("my_crate", LevelFilter::Info)
.init()
.unwrap();Sourcepub fn with_target_levels(
self,
target_levels: HashMap<String, LevelFilter>,
) -> Logger
👎Deprecated since 1.11.0: Use with_module_level instead. Will be removed in version 2.0.0.
pub fn with_target_levels( self, target_levels: HashMap<String, LevelFilter>, ) -> Logger
with_module_level instead. Will be removed in version 2.0.0.Override the log level for specific targets.
Sourcepub fn with_timestamp_format(self, format: &String) -> Logger
pub fn with_timestamp_format(self, format: &String) -> Logger
Control the format used for timestamps.
Without this, a default format is used depending on the timestamps type.
The syntax for the format can be found in the
chrono crate book.
lite_log::LiteLogger::new()
.with_level(log::LevelFilter::Debug)
.env()
.with_timestamp_format(&String::from("%Y-%m-%d %H:%M:%S"))
.init()
.unwrap();Sourcepub fn without_timestamps(self) -> Logger
pub fn without_timestamps(self) -> Logger
Don’t display any timestamps.
This method is only available if the timestamps feature is enabled.
Sourcepub fn with_local_timestamps(self) -> Logger
pub fn with_local_timestamps(self) -> Logger
Display timestamps using the local timezone.
This method is only available if the timestamps feature is enabled.
Sourcepub fn with_utc_timestamps(self) -> Logger
pub fn with_utc_timestamps(self) -> Logger
Display timestamps using UTC.
This method is only available if the timestamps feature is enabled.
Sourcepub fn with_utc_offset(self, offset: i32) -> Logger
pub fn with_utc_offset(self, offset: i32) -> Logger
Display timestamps using a static UTC offset.
This method is only available if the timestamps feature is enabled.
Sourcepub fn with_colors(self, colors: bool) -> Logger
pub fn with_colors(self, colors: bool) -> Logger
Control whether messages are colored or not.
This method is only available if the colored feature is enabled.
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.