[][src]Module fern::colors

Support for ANSI terminal colors via the colored crate.

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

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

Colors are mainly supported via coloring the log level itself, but it's also possible to color each entire log line based off of the log level.

First, here's an example which colors the log levels themselves ("INFO" / "WARN" text will have color, but won't color the rest of the line). ColoredLevelConfig lets us configure the colors per-level, but also has sane defaults.

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

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

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

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

Coloring levels is nice, but the alternative is good to. For an example application coloring each entire log line with the right color, see examples/pretty-colored.rs.



Configuration specifying colors a log level can be colored as.


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



The 8 standard colors.