Struct r3bl_simple_logger::ConfigBuilder
source · #[non_exhaustive]pub struct ConfigBuilder(/* private fields */);
Expand description
Builder for the Logger Configurations (Config
)
All loggers print the message in the following form:
00:00:00 [LEVEL] crate::module: [lib.rs::100] your_message
Every space delimited part except the actual message is optional.
Use this struct to create a custom Config
changing when these information shall
be logged. Every part can be enabled for a specific Level and is then
automatically enable for all lower levels as well.
The Result is that the logging gets more detailed the more verbose it gets.
E.g. to have one part shown always use Level::Error
. But if you
want to show the source line only on Trace
use that.
Implementations§
source§impl ConfigBuilder
impl ConfigBuilder
sourcepub fn new() -> ConfigBuilder
pub fn new() -> ConfigBuilder
Create a new default ConfigBuilder
Examples found in repository?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Magenta))
.set_level_color(Level::Trace, Some(Color::Green))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Magenta error");
warn!("Yellow warning");
info!("Blue info");
debug!("Cyan debug");
trace!("Green trace");
}
More examples
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Rgb(191, 0, 0)))
.set_level_color(Level::Warn, Some(Color::Rgb(255, 127, 0)))
.set_level_color(Level::Info, Some(Color::Rgb(192, 192, 0)))
.set_level_color(Level::Debug, Some(Color::Rgb(63, 127, 0)))
.set_level_color(Level::Trace, Some(Color::Rgb(127, 127, 255)))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Red error");
warn!("Orange warning");
info!("Yellow info");
debug!("Dark green debug");
trace!("Light blue trace");
}
sourcepub fn set_max_level(&mut self, level: LevelFilter) -> &mut ConfigBuilder
pub fn set_max_level(&mut self, level: LevelFilter) -> &mut ConfigBuilder
Set at which level and above (more verbose) the level itself shall be logged (default is Error)
sourcepub fn set_time_level(&mut self, time: LevelFilter) -> &mut ConfigBuilder
pub fn set_time_level(&mut self, time: LevelFilter) -> &mut ConfigBuilder
Set at which level and above (more verbose) the current time shall be logged (default is Error)
sourcepub fn set_thread_level(&mut self, thread: LevelFilter) -> &mut ConfigBuilder
pub fn set_thread_level(&mut self, thread: LevelFilter) -> &mut ConfigBuilder
Set at which level and above (more verbose) the thread id shall be logged. (default is Debug)
sourcepub fn set_target_level(&mut self, target: LevelFilter) -> &mut ConfigBuilder
pub fn set_target_level(&mut self, target: LevelFilter) -> &mut ConfigBuilder
Set at which level and above (more verbose) the target shall be logged. (default is Debug)
sourcepub fn set_target_padding(
&mut self,
padding: TargetPadding
) -> &mut ConfigBuilder
pub fn set_target_padding( &mut self, padding: TargetPadding ) -> &mut ConfigBuilder
Set how the thread should be padded
sourcepub fn set_location_level(
&mut self,
location: LevelFilter
) -> &mut ConfigBuilder
pub fn set_location_level( &mut self, location: LevelFilter ) -> &mut ConfigBuilder
Set at which level and above (more verbose) a source code reference shall be logged (default is Trace)
sourcepub fn set_module_level(&mut self, module: LevelFilter) -> &mut ConfigBuilder
pub fn set_module_level(&mut self, module: LevelFilter) -> &mut ConfigBuilder
Set at which level and above (more verbose) a module shall be logged (default is Off)
sourcepub fn set_level_padding(&mut self, padding: LevelPadding) -> &mut ConfigBuilder
pub fn set_level_padding(&mut self, padding: LevelPadding) -> &mut ConfigBuilder
Set how the levels should be padded, when logging (default is Off)
sourcepub fn set_thread_padding(
&mut self,
padding: ThreadPadding
) -> &mut ConfigBuilder
pub fn set_thread_padding( &mut self, padding: ThreadPadding ) -> &mut ConfigBuilder
Set how the thread should be padded
sourcepub fn set_thread_mode(&mut self, mode: ThreadLogMode) -> &mut ConfigBuilder
pub fn set_thread_mode(&mut self, mode: ThreadLogMode) -> &mut ConfigBuilder
Set the mode for logging the thread
sourcepub fn set_level_color(
&mut self,
level: Level,
color: Option<Color>
) -> &mut ConfigBuilder
pub fn set_level_color( &mut self, level: Level, color: Option<Color> ) -> &mut ConfigBuilder
Set the color used for printing the level (if the logger supports it), or None to use the default foreground color
Examples found in repository?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Magenta))
.set_level_color(Level::Trace, Some(Color::Green))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Magenta error");
warn!("Yellow warning");
info!("Blue info");
debug!("Cyan debug");
trace!("Green trace");
}
More examples
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Rgb(191, 0, 0)))
.set_level_color(Level::Warn, Some(Color::Rgb(255, 127, 0)))
.set_level_color(Level::Info, Some(Color::Rgb(192, 192, 0)))
.set_level_color(Level::Debug, Some(Color::Rgb(63, 127, 0)))
.set_level_color(Level::Trace, Some(Color::Rgb(127, 127, 255)))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Red error");
warn!("Orange warning");
info!("Yellow info");
debug!("Dark green debug");
trace!("Light blue trace");
}
sourcepub fn set_time_format_custom(
&mut self,
time_format: &'static [FormatItem<'static>]
) -> &mut ConfigBuilder
pub fn set_time_format_custom( &mut self, time_format: &'static [FormatItem<'static>] ) -> &mut ConfigBuilder
Sets the time format to a custom representation.
The easiest way to satisfy the static lifetime of the argument is to directly use the
re-exported time::macros::format_description
macro.
Note: The default time format is [hour]:[minute]:[second]
.
The syntax for the format_description macro can be found in the
time
crate book.
Usage
let config = ConfigBuilder::new()
.set_time_format_custom(format_description!("[hour]:[minute]:[second].[subsecond]"))
.build();
sourcepub fn set_time_format_rfc2822(&mut self) -> &mut ConfigBuilder
pub fn set_time_format_rfc2822(&mut self) -> &mut ConfigBuilder
Set time format string to use rfc2822.
sourcepub fn set_time_format_rfc3339(&mut self) -> &mut ConfigBuilder
pub fn set_time_format_rfc3339(&mut self) -> &mut ConfigBuilder
Set time format string to use rfc3339.
sourcepub fn set_time_offset(&mut self, offset: UtcOffset) -> &mut ConfigBuilder
pub fn set_time_offset(&mut self, offset: UtcOffset) -> &mut ConfigBuilder
Set offset used for logging time (default is UTC)
sourcepub fn set_write_log_enable_colors(&mut self, local: bool) -> &mut ConfigBuilder
pub fn set_write_log_enable_colors(&mut self, local: bool) -> &mut ConfigBuilder
set if you want to write colors in the logfile (default is Off)
sourcepub fn add_filter_allow_str(
&mut self,
filter_allow: &'static str
) -> &mut ConfigBuilder
pub fn add_filter_allow_str( &mut self, filter_allow: &'static str ) -> &mut ConfigBuilder
Add allowed target filters. If any are specified, only records from targets matching one of these entries will be printed
For example, add_filter_allow_str("tokio::uds")
would allow only logging from the tokio
crates uds
module.
sourcepub fn add_filter_allow(&mut self, filter_allow: String) -> &mut ConfigBuilder
pub fn add_filter_allow(&mut self, filter_allow: String) -> &mut ConfigBuilder
Add allowed target filters. If any are specified, only records from targets matching one of these entries will be printed
For example, add_filter_allow(format!("{}::{}","tokio", "uds"))
would allow only logging from the tokio
crates uds
module.
sourcepub fn clear_filter_allow(&mut self) -> &mut ConfigBuilder
pub fn clear_filter_allow(&mut self) -> &mut ConfigBuilder
Clear allowed target filters. If none are specified, nothing is filtered out
sourcepub fn add_filter_ignore_str(
&mut self,
filter_ignore: &'static str
) -> &mut ConfigBuilder
pub fn add_filter_ignore_str( &mut self, filter_ignore: &'static str ) -> &mut ConfigBuilder
Add denied target filters. If any are specified, records from targets matching one of these entries will be ignored
For example, add_filter_ignore_str("tokio::uds")
would deny logging from the tokio
crates uds
module.
sourcepub fn add_filter_ignore(&mut self, filter_ignore: String) -> &mut ConfigBuilder
pub fn add_filter_ignore(&mut self, filter_ignore: String) -> &mut ConfigBuilder
Add denied target filters. If any are specified, records from targets matching one of these entries will be ignored
For example, add_filter_ignore(format!("{}::{}","tokio", "uds"))
would deny logging from the tokio
crates uds
module.
sourcepub fn clear_filter_ignore(&mut self) -> &mut ConfigBuilder
pub fn clear_filter_ignore(&mut self) -> &mut ConfigBuilder
Clear ignore target filters. If none are specified, nothing is filtered
sourcepub fn build(&mut self) -> Config
pub fn build(&mut self) -> Config
Build new Config
Examples found in repository?
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Magenta))
.set_level_color(Level::Trace, Some(Color::Green))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Magenta error");
warn!("Yellow warning");
info!("Blue info");
debug!("Cyan debug");
trace!("Green trace");
}
More examples
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
fn main() {
let config = ConfigBuilder::new()
.set_level_color(Level::Error, Some(Color::Rgb(191, 0, 0)))
.set_level_color(Level::Warn, Some(Color::Rgb(255, 127, 0)))
.set_level_color(Level::Info, Some(Color::Rgb(192, 192, 0)))
.set_level_color(Level::Debug, Some(Color::Rgb(63, 127, 0)))
.set_level_color(Level::Trace, Some(Color::Rgb(127, 127, 255)))
.build();
TermLogger::init(
LevelFilter::Trace,
config,
TerminalMode::Stdout,
ColorChoice::Auto,
)
.unwrap();
error!("Red error");
warn!("Orange warning");
info!("Yellow info");
debug!("Dark green debug");
trace!("Light blue trace");
}
Trait Implementations§
source§impl Clone for ConfigBuilder
impl Clone for ConfigBuilder
source§fn clone(&self) -> ConfigBuilder
fn clone(&self) -> ConfigBuilder
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more