Struct env_logger::fmt::Formatter[][src]

pub struct Formatter { /* fields omitted */ }

A formatter to write logs into.

Formatter implements the standard Write trait for writing log records. It also supports terminal colors, through the style method.

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[src]

pub fn timestamp(&self) -> Timestamp[src]

Get a Timestamp for 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())
});

pub fn timestamp_seconds(&self) -> Timestamp[src]

Get a Timestamp for the current date and time in UTC with full second precision.

pub fn timestamp_millis(&self) -> Timestamp[src]

Get a Timestamp for the current date and time in UTC with millisecond precision.

pub fn timestamp_micros(&self) -> Timestamp[src]

Get a Timestamp for the current date and time in UTC with microsecond precision.

pub fn timestamp_nanos(&self) -> Timestamp[src]

Get a Timestamp for the current date and time in UTC with nanosecond precision.

impl Formatter[src]

pub fn style(&self) -> Style[src]

Begin a new Style.

Examples

Create a bold, red colored style and use it to print the log level:

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())
});

pub fn default_level_style(&self, level: Level) -> Style[src]

Get the default Style for the given level.

The style can be used to print other values besides the level.

pub fn default_styled_level(&self, level: Level) -> StyledValue<'static, Level>[src]

Get a printable Style for the given level.

The style can only be used to print the level.

Trait Implementations

impl Debug for Formatter[src]

impl Write for Formatter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.