[−][src]Struct env_logger::fmt::Formatter
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()));
Methods
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]
fn write(&mut self, buf: &[u8]) -> Result<usize>[src]
fn flush(&mut self) -> Result<()>[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize, Error>1.36.0[src]
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>1.0.0[src]
fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>1.0.0[src]
fn by_ref(&mut self) -> &mut Self1.0.0[src]
Auto Trait Implementations
impl !RefUnwindSafe for Formatter
impl !Send for Formatter
impl !Sync for Formatter
impl Unpin for Formatter
impl !UnwindSafe for Formatter
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,