Module fern::colors [] [src]

Support for ANSI terminal colors via the colored crate.

To enable support for colors, add the "colored" feature in your Cargo.toml:

[dependencies]
fern = { version = "0.5", features = ["colored"] }

Colors are currently supported mainly for the log-level. Meaning you can configure the "INFO" / "WARN" / "ERROR" text itself to be a different color depending on which of those it is.

To do this, the ColoredLevelConfig structure allows configuration of per-level colors.

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


let mut colors = ColoredLevelConfig::new()
    // use builder methods
    .info(Color::Green);
// or access raw fields
colors.warn = Color::Magenta;

It can then be used within any regular fern formatting closure:

fern::Dispatch::new()
    // ...
    .format(move |out, message, record| {
        out.finish(format_args!(
            "[{}] {}",
            // just use 'colors.color(..)' instead of the level
            // itself to insert ANSI colors.
            colors.color(record.level()),
            message,
        ))
    })

Structs

ColoredLevelConfig

Configuration specifying colors a log level can be colored as.

WithFgColor

Opaque structure which represents some text data and a color to display it with.

Enums

Color

The 8 standard colors.