pub struct HumanFormat { /* private fields */ }human only.Expand description
Human-readable formatter.
Message and target are written as-is except that control
characters, DEL, C1 controls, U+2028/U+2029 and bidi controls are
escaped (\n, \x1b, \u{85}, …), so hostile input can neither
break the one-record-per-line layout nor drive the terminal. Values
are quoted when they are empty or contain whitespace, =, ", \
or a special character. Keys are sanitized: whitespace, =, " and
special characters become _.
Backslashes in unquoted text are not escaped, so a message that
literally contains \n renders the same as one containing a
newline. The format is meant for people; use JSON or logfmt where
output must be parsed back exactly.
Colour is off by default. HumanFormat::color turns ANSI colour
on for the level column (and dims the target); the
LoggerBuilder::stdout_human / stderr_human shortcuts enable it
automatically when the stream is a terminal (see ColorChoice, available
with the std feature).
§Examples
use log_io::format::{Format, HumanFormat};
use log_io::{Field, Level, Metadata, Record};
let fields = [Field::new("port", 8080_u32), Field::new("note", "two words")];
let record = Record::new(Metadata::new(Level::Info, "app"), "ok\x1b[2J", &fields);
let mut out = String::new();
HumanFormat::new().write_record(&record, &mut out)?;
assert_eq!(out, "INFO [app] ok\\x1b[2J port=8080 note=\"two words\"\n");Implementations§
Source§impl HumanFormat
impl HumanFormat
Sourcepub const fn show_target(self, enabled: bool) -> Self
pub const fn show_target(self, enabled: bool) -> Self
Toggle the [target] column. The column is always omitted for
records with an empty target.
Sourcepub const fn show_source_location(self, enabled: bool) -> Self
pub const fn show_source_location(self, enabled: bool) -> Self
Toggle the (file:line) suffix for records that carry a source
location.