Struct handsome_logger::ConfigBuilder
source · pub struct ConfigBuilder(/* private fields */);
Implementations§
source§impl ConfigBuilder
impl ConfigBuilder
pub fn new() -> ConfigBuilder
sourcepub fn new_preset_config_full() -> ConfigBuilder
pub fn new_preset_config_full() -> ConfigBuilder
Preset for saving bigger amount of information than default preset
pub fn new_preset_no_micros_in_time() -> ConfigBuilder
sourcepub fn set_format_text(
&mut self,
format_text: &'static str,
level: Option<LevelFilter>
) -> &mut ConfigBuilder
pub fn set_format_text( &mut self, format_text: &'static str, level: Option<LevelFilter> ) -> &mut ConfigBuilder
Sets format of logged message E.g. “[_time] [[_level]] [_module] "[_msg]"” depending on other settings, may print something like: 14:21:15 [INFO] main: “Hello world!” If level is none, it will set all levels
sourcepub fn set_background_color(
&mut self,
background_color: Option<Color>,
level: Option<LevelFilter>
) -> &mut ConfigBuilder
pub fn set_background_color( &mut self, background_color: Option<Color>, level: Option<LevelFilter> ) -> &mut ConfigBuilder
Sets background color
If color is none, background will not be colored
If level is none, it will set all levels
If level is some, it will set only that level
Background color is used only if enabled_colors
is true
sourcepub fn set_colored_text_color(
&mut self,
colored_text_color: Option<Color>,
level: Option<LevelFilter>
) -> &mut ConfigBuilder
pub fn set_colored_text_color( &mut self, colored_text_color: Option<Color>, level: Option<LevelFilter> ) -> &mut ConfigBuilder
Sets text color
If color is none, text will be invisible
If level is none, it will set all levels
If level is some, it will set only that level
Background color is used only if enabled_colors
is true
sourcepub fn set_enabled_colours(
&mut self,
enabled_colours: bool
) -> &mut ConfigBuilder
pub fn set_enabled_colours( &mut self, enabled_colours: bool ) -> &mut ConfigBuilder
Enables colouring of text - only works with TermLogger
sourcepub fn set_level(&mut self, level: LevelFilter) -> &mut ConfigBuilder
pub fn set_level(&mut self, level: LevelFilter) -> &mut ConfigBuilder
Sets the level of the logger.
E.g. using LevelFilter::Info
will print all logs with level Info
, Warn
, Error
,
but not Debug
or Trace
.
sourcepub fn set_write_once(&mut self, write_once: bool) -> &mut ConfigBuilder
pub fn set_write_once(&mut self, write_once: bool) -> &mut ConfigBuilder
Instead of writing multiple times to target, creates a buffer, writes to memory and
at the end writes only once to target
This is useful when saving to file, because allows to not split one log into multiple
files if rotating is used.
Works only with WriteLogger
sourcepub fn set_time_format(
&mut self,
time_format: TimeFormat,
level: Option<LevelFilter>
) -> &mut ConfigBuilder
pub fn set_time_format( &mut self, time_format: TimeFormat, level: Option<LevelFilter> ) -> &mut ConfigBuilder
Set time format used in logger If level is none, it will set all levels Time format can be predefined(Rfc2822 or Rfc3339) or custom
sourcepub fn set_time_offset(&mut self, offset: UtcOffset) -> &mut ConfigBuilder
pub fn set_time_offset(&mut self, offset: UtcOffset) -> &mut ConfigBuilder
Manually sets the offset used for the time.
sourcepub fn set_time_offset_to_local(
&mut self
) -> Result<&mut ConfigBuilder, &mut ConfigBuilder>
pub fn set_time_offset_to_local( &mut self ) -> Result<&mut ConfigBuilder, &mut ConfigBuilder>
Sets the offset used to the current local time offset
sourcepub fn set_remove_time_offset(&mut self) -> &mut ConfigBuilder
pub fn set_remove_time_offset(&mut self) -> &mut ConfigBuilder
Reset the offset used to UTC
sourcepub fn set_message_filtering<F>(
&mut self,
message_filtering: Option<F>
) -> &mut ConfigBuilderwhere
F: Fn(&Record<'_>) -> bool + Send + Sync + 'static,
pub fn set_message_filtering<F>( &mut self, message_filtering: Option<F> ) -> &mut ConfigBuilderwhere F: Fn(&Record<'_>) -> bool + Send + Sync + 'static,
Sets function that will be used to filter messages
If function returns true, message will be logged, otherwise it will be ignored
Function takes as argument function that will be filtered allowed results
If message_filtering
is none, all messages will be logged
use log::{info, Record};
use handsome_logger::{Config, ConfigBuilder};
fn filtering_messages(record: &Record) -> bool {
if let Some(arg) = record.args().as_str() {
!arg.contains("E")
} else {
true
}
}
let logger = ConfigBuilder::new().set_message_filtering(Some(filtering_messages)).build();
info!("Got BED"); // This will be ignored
info!("Got ANANAS"); // This will be printed
sourcepub fn set_custom_write_formatter<F>(
&mut self,
write_formatter: Option<F>
) -> &mut ConfigBuilderwhere
F: Fn(&Record<'_>, &mut dyn Write) -> Result<(), Error> + Send + Sync + 'static,
pub fn set_custom_write_formatter<F>( &mut self, write_formatter: Option<F> ) -> &mut ConfigBuilderwhere F: Fn(&Record<'_>, &mut dyn Write) -> Result<(), Error> + Send + Sync + 'static,
Sets custom formatter for WriteLogger
If you don’t want to use default formatter, you can set your own
Setting write_formatter
to None will use default formatter
Function takes as argument function that will be filtered allowed results
sourcepub fn set_custom_terminal_formatter<F>(
&mut self,
terminal_formatter: Option<F>
) -> &mut ConfigBuilderwhere
F: Fn(&Record<'_>, &mut BufferedStandardStream) -> Result<(), Error> + Send + Sync + 'static,
pub fn set_custom_terminal_formatter<F>( &mut self, terminal_formatter: Option<F> ) -> &mut ConfigBuilderwhere F: Fn(&Record<'_>, &mut BufferedStandardStream) -> Result<(), Error> + Send + Sync + 'static,
Sets custom formatter for TermLogger
If you don’t want to use default formatter, you can set your own
Setting terminal_formatter
to None will use default formatter
Function takes as argument function that will be filtered allowed results
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