pub struct ColoredLevelConfig {
    pub error: Color,
    pub warn: Color,
    pub info: Color,
    pub debug: Color,
    pub trace: Color,
}
Expand description

Configuration specifying colors a log level can be colored as.

Example usage setting custom ‘info’ and ‘debug’ colors:

use fern::colors::{Color, ColoredLevelConfig};

let colors = ColoredLevelConfig::new()
    .info(Color::Green)
    .debug(Color::Magenta);

fern::Dispatch::new()
    .format(move |out, message, record| {
        out.finish(format_args!(
            "[{}] {}",
            colors.color(record.level()),
            message
        ))
    })
    .chain(std::io::stdout())
    .apply()?;

Fields§

§error: Color

The color to color logs with the Error level.

§warn: Color

The color to color logs with the Warn level.

§info: Color

The color to color logs with the Info level.

§debug: Color

The color to color logs with the Debug level.

§trace: Color

The color to color logs with the Trace level.

Implementations§

source§

impl ColoredLevelConfig

source

pub fn new() -> Self

Creates a new ColoredLevelConfig with the default colors.

This matches the behavior of ColoredLevelConfig::default.

source

pub fn error(self, error: Color) -> Self

Overrides the Error level color with the given color.

The default color is Color::Red.

source

pub fn warn(self, warn: Color) -> Self

Overrides the Warn level color with the given color.

The default color is Color::Yellow.

source

pub fn info(self, info: Color) -> Self

Overrides the Info level color with the given color.

The default color is Color::White.

source

pub fn debug(self, debug: Color) -> Self

Overrides the Debug level color with the given color.

The default color is Color::White.

source

pub fn trace(self, trace: Color) -> Self

Overrides the Trace level color with the given color.

The default color is Color::White.

source

pub fn color(&self, level: Level) -> WithFgColor<Level>

Colors the given log level with the color in this configuration corresponding to it’s level.

The structure returned is opaque, but will print the Level surrounded by ANSI color codes when displayed. This will work correctly for UNIX terminals, but due to a lack of support from the colored crate, this will not function in Windows.

source

pub fn get_color(&self, level: &Level) -> Color

Retrieves the color that a log level should be colored as.

Trait Implementations§

source§

impl Clone for ColoredLevelConfig

source§

fn clone(&self) -> ColoredLevelConfig

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 Default for ColoredLevelConfig

source§

fn default() -> Self

Retrieves the default configuration. This has:

source§

impl Copy for ColoredLevelConfig

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.