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 easily format a log record:

use std::io::Write;

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

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

Methods

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

Get the default Style for the given level.

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

Get a PreciseTimestamp for the current date and time in UTC with nanos.

Trait Implementations

impl Write for Formatter
[src]

Write a buffer into this object, returning how many bytes were written. Read more

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

Attempts to write an entire buffer into this write. Read more

Writes a formatted string into this writer, returning any error encountered. Read more

Creates a "by reference" adaptor for this instance of Write. Read more

impl Debug for Formatter
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl !Send for Formatter

impl !Sync for Formatter