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]
impl Formatter
pub fn style(&self) -> Style
[src]
pub fn style(&self) -> Style
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 timestamp(&self) -> Timestamp
[src]
pub fn timestamp(&self) -> Timestamp
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]
impl Write for Formatter
fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
[src]
fn flush(&mut self) -> Result<()>
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]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this write. Read more
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>
Writes a formatted string into this writer, returning any error encountered. Read more
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn by_ref(&mut self) -> &mut Self
Creates a "by reference" adaptor for this instance of Write
. Read more
impl Debug for Formatter
[src]
impl Debug for Formatter