Struct Formatter
pub struct Formatter { /* private fields */ }
A formatter to write logs into.
Formatter implements the standard Write trait for writing log records.
It also supports terminal styling using ANSI escape codes.
Examples
Use the writeln macro to format a log record.
An instance of a Formatter is passed to an env_logger format as buf:
use std::io::Write;
let mut builder = env_logger::Builder::new();
builder.format(|buf, record| writeln!(buf, "{}: {}", record.level(), record.args()));
Implementations
impl Formatter
fn default_level_style(&self, level: Level) -> StyleGet the default
style::Stylefor the given level.The style can be used to print other values besides the level.
See
stylefor how to adapt it to the styling crate of your choice
impl Formatter
fn timestamp(&self) -> TimestampGet a
Timestampfor the current date and time in UTC.Examples
Include the current timestamp with the log record:
use std::io::Write; let mut builder = env_logger::Builder::new(); builder.format(|buf, record| { let ts = buf.timestamp(); writeln!(buf, "{}: {}: {}", ts, record.level(), record.args()) });fn timestamp_seconds(&self) -> TimestampGet a
Timestampfor the current date and time in UTC with full second precision.fn timestamp_millis(&self) -> TimestampGet a
Timestampfor the current date and time in UTC with millisecond precision.fn timestamp_micros(&self) -> TimestampGet a
Timestampfor the current date and time in UTC with microsecond precision.fn timestamp_nanos(&self) -> TimestampGet a
Timestampfor the current date and time in UTC with nanosecond precision.
Trait Implementations
impl Debug for Formatter
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Write for Formatter
fn write(&mut self, buf: &[u8]) -> Result<usize>fn flush(&mut self) -> Result<()>