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]
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()) });
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()) });
Trait Implementations
impl Write for Formatter
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
[src]
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Creates a "by reference" adaptor for this instance of Write
. Read more