[−][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 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.
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 precise_timestamp(&self) -> PreciseTimestamp
[src]
Get a [PreciseTimestamp
] for the current date and time in UTC with nanos.
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]
Like write
, except that it writes from a slice of buffers. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
Attempts to write an entire buffer into this writer. 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
Auto Trait Implementations
impl Unpin for Formatter
impl !Sync for Formatter
impl !Send for Formatter
impl !UnwindSafe for Formatter
impl !RefUnwindSafe for Formatter
Blanket Implementations
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,