Struct simple_logger::SimpleLogger [−][src]
pub struct SimpleLogger { /* fields omitted */ }
Expand description
Implementations
Initializes the global logger with a SimpleLogger instance with
default log level set to Level::Trace
.
use simple_logger::SimpleLogger;
SimpleLogger::new().env().init().unwrap();
log::warn!("This is an example message.");
👎 Deprecated since 1.12.0: Use env
instead. Will be removed in version 2.0.0.
Use 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 simple_logger::SimpleLogger;
SimpleLogger::from_env().init().unwrap();
log::warn!("This is an example message.");
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.
Set the ‘default’ log level.
You can override the default level for specific modules and their sub-modules using with_module_level
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 simple_logger::SimpleLogger;
use log::LevelFilter;
SimpleLogger::new().with_module_level("chatty_dependency", LevelFilter::Warn).init().unwrap();
Disable logging for all dependencies:
use simple_logger::SimpleLogger;
use log::LevelFilter;
SimpleLogger::new()
.with_level(LevelFilter::Off)
.with_module_level("my_crate", LevelFilter::Info)
.init()
.unwrap();
👎 Deprecated since 1.11.0: Use with_module_level
instead. Will be removed in version 2.0.0.
Use with_module_level
instead. Will be removed in version 2.0.0.
Override the log level for specific targets.
👎 Deprecated since 1.16.0: Use [with_local_timestamps
] or [with_utc_timestamps
] instead. Will be removed in version 2.0.0.
Use [with_local_timestamps
] or [with_utc_timestamps
] instead. Will be removed in version 2.0.0.
Control whether timestamps are printed or not.
Timestamps will be displayed in the local timezone.
This method is only available if the timestamps
feature is enabled.
Don’t display any timestamps.
This method is only available if the timestamps
feature is enabled.
Display timestamps using the local timezone.
This method is only available if the timestamps
feature is enabled.
Display timestamps using UTC.
This method is only available if the timestamps
feature is enabled.
Control whether messages are colored or not.
This method is only available if the colored
feature is enabled.
‘Init’ the actual logger, instantiate it and configure it, this method MUST be called in order for the logger to be effective.