[][src]Struct fern::colors::ColoredLevelConfig

#[must_use = "builder methods take config by value and thus must be reassigned to variable"]
pub struct ColoredLevelConfig { pub error: Color, pub warn: Color, pub info: Color, pub debug: Color, pub trace: Color, }

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.

Methods

impl ColoredLevelConfig[src]

pub fn new() -> Self[src]

Creates a new ColoredLevelConfig with the default colors.

This matches the behavior of ColoredLevelConfig::default.

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

Overrides the Error level color with the given color.

The default color is Color::Red.

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

Overrides the Warn level color with the given color.

The default color is Color::Yellow.

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

Overrides the Info level color with the given color.

The default color is Color::White.

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

Overrides the Debug level color with the given color.

The default color is Color::White.

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

Overrides the Trace level color with the given color.

The default color is Color::White.

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

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.

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

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

Trait Implementations

impl Copy for ColoredLevelConfig[src]

impl Default for ColoredLevelConfig[src]

fn default() -> Self[src]

Retrieves the default configuration. This has:

impl Clone for ColoredLevelConfig[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.