Module env_logger::fmt

source ·
Expand description

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.

Terminal styling is done through ANSI escape codes and will be adapted to the capabilities of the target stream. For example, you could use one of:

use std::io::Write;

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

builder.format(|buf, record| {
    writeln!(buf, "{}: {}",
        record.level(),
        record.args())
});

§Key Value arguments

If the unstable-kv feature is enabled, then the default format will include key values from the log by default, but this can be disabled by calling Builder::format_key_values with [hidden_kv_format] as the format function.

The way these keys and values are formatted can also be customized with a separate format function that is called by the default format with Builder::format_key_values.

use log::info;
env_logger::init();
info!(x="45"; "Some message");
info!(x="12"; "Another message {x}", x="12");

See https://docs.rs/log/latest/log/#structured-logging.

Re-exports§

Structs§

Enums§