#[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

source

pub fn new() -> ConfigBuilder

Create a new default ConfigBuilder

Examples found in repository?
examples/custom_colors.rs (line 8)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
Hide additional examples
examples/rgb_colors.rs (line 12)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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");
}
source

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)

source

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)

source

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)

source

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)

source

pub fn set_target_padding( &mut self, padding: TargetPadding ) -> &mut ConfigBuilder

Set how the thread should be padded

source

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)

source

pub fn set_level_padding(&mut self, padding: LevelPadding) -> &mut ConfigBuilder

Set how the levels should be padded, when logging (default is Off)

source

pub fn set_thread_padding( &mut self, padding: ThreadPadding ) -> &mut ConfigBuilder

Set how the thread should be padded

source

pub fn set_thread_mode(&mut self, mode: ThreadLogMode) -> &mut ConfigBuilder

Set the mode for logging the thread

source

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?
examples/custom_colors.rs (line 9)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
Hide additional examples
examples/rgb_colors.rs (line 13)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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");
}
source

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();
source

pub fn set_time_format_rfc2822(&mut self) -> &mut ConfigBuilder

Set time format string to use rfc2822.

source

pub fn set_time_format_rfc3339(&mut self) -> &mut ConfigBuilder

Set time format string to use rfc3339.

source

pub fn set_time_offset(&mut self, offset: UtcOffset) -> &mut ConfigBuilder

Set offset used for logging time (default is UTC)

source

pub fn set_time_offset_to_local( &mut self ) -> Result<&mut ConfigBuilder, &mut ConfigBuilder>

Sets the offset used to the current local time offset (overriding values previously set by ConfigBuilder::set_time_offset).

This function may fail if the offset cannot be determined soundly. This may be the case, when the program is multi-threaded by the time of calling this function. One can opt-out of this behavior by setting RUSTFLAGS="--cfg unsound_local_offset". Doing so is not recommended, completely untested and may cause unexpected segfaults.

source

pub fn add_filter_allow_str( &mut self, filter_allow: &'static str ) -> &mut ConfigBuilder

Add allowed module filters. If any are specified, only records from modules starting with 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.

source

pub fn add_filter_allow(&mut self, filter_allow: String) -> &mut ConfigBuilder

Add allowed module filters. If any are specified, only records from modules starting with 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.

source

pub fn clear_filter_allow(&mut self) -> &mut ConfigBuilder

Clear allowed module filters. If none are specified, nothing is filtered out

source

pub fn add_filter_ignore_str( &mut self, filter_ignore: &'static str ) -> &mut ConfigBuilder

Add denied module filters. If any are specified, records from modules starting with one of these entries will be ignored

For example, add_filter_ignore_str("tokio::uds") would deny logging from the tokio crates uds module.

source

pub fn add_filter_ignore(&mut self, filter_ignore: String) -> &mut ConfigBuilder

Add denied module filters. If any are specified, records from modules starting with one of these entries will be ignored

For example, add_filter_ignore(format!("{}{}","tokio", "uds")) would deny logging from the tokio crates uds module.

source

pub fn clear_filter_ignore(&mut self) -> &mut ConfigBuilder

Clear ignore module filters. If none are specified, nothing is filtered

source

pub fn build(&mut self) -> Config

Build new Config

Examples found in repository?
examples/custom_colors.rs (line 11)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
Hide additional examples
examples/rgb_colors.rs (line 18)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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

source§

fn clone(&self) -> ConfigBuilder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ConfigBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ConfigBuilder

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.