Module env_logger::fmt [] [src]

Formatting for log records.

This module contains a Formatter that can be used to format log records into without needing temporary allocations. Usually you won't need to worry about the contents of this module and can use the Formatter like an ordinary Write.

Formatting log records

The format used to print log records can be customised using the Builder::format method. Custom formats can apply different color and weight to printed values using Style builders.

use std::io::Write;
use env_logger::fmt::Color;

let mut builder = env_logger::Builder::new();

builder.format(|buf, record| {
    let mut level_style = buf.style();

    level_style.set_color(Color::Red).set_bold(true);

    writeln!(buf, "{}: {}",
        level_style.value(record.level()),
        record.args())
});

Structs

Formatter

A formatter to write logs into.

ParseColorError

An error from parsing an invalid color specification.

Style

A set of styles to apply to the terminal output.

StyledValue

A value that can be printed using the given styles.

Timestamp

An RFC3339 formatted timestamp.

Enums

Color

The set of available colors for the terminal foreground/background.

Target

Log target, either stdout or stderr.

WriteStyle

Whether or not to print styles to the target.