Struct Formatter

Source
pub struct Formatter { /* private fields */ }
Expand description

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

Implementations§

Source§

impl Formatter

Source

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

pub fn timestamp_seconds(&self) -> Timestamp

Get a Timestamp for the current date and time in UTC with full second precision.

Source

pub fn timestamp_millis(&self) -> Timestamp

Get a Timestamp for the current date and time in UTC with millisecond precision.

Source

pub fn timestamp_micros(&self) -> Timestamp

Get a Timestamp for the current date and time in UTC with microsecond precision.

Source

pub fn timestamp_nanos(&self) -> Timestamp

Get a Timestamp for the current date and time in UTC with nanosecond precision.

Source§

impl Formatter

Source

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

pub fn default_level_style(&self, level: Level) -> Style

Get the default Style for the given level.

The style can be used to print other values besides the level.

Source

pub fn default_styled_level(&self, level: Level) -> StyledValue<'static, Level>

Get a printable Style for the given level.

The style can only be used to print the level.

Trait Implementations§

Source§

impl Debug for Formatter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Write for Formatter

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Error>

Writes a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), Error>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. Read more
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. Read more
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<W> WriteBytesExt for W
where W: Write + ?Sized,

Source§

fn write_u8(&mut self, n: u8) -> Result<(), Error>

Writes an unsigned 8 bit integer to the underlying writer. Read more
Source§

fn write_i8(&mut self, n: i8) -> Result<(), Error>

Writes a signed 8 bit integer to the underlying writer. Read more
Source§

fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 16 bit integer to the underlying writer. Read more
Source§

fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 16 bit integer to the underlying writer. Read more
Source§

fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 24 bit integer to the underlying writer. Read more
Source§

fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 24 bit integer to the underlying writer. Read more
Source§

fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 32 bit integer to the underlying writer. Read more
Source§

fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 32 bit integer to the underlying writer. Read more
Source§

fn write_u48<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 48 bit integer to the underlying writer. Read more
Source§

fn write_i48<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 48 bit integer to the underlying writer. Read more
Source§

fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 64 bit integer to the underlying writer. Read more
Source§

fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 64 bit integer to the underlying writer. Read more
Source§

fn write_u128<T>(&mut self, n: u128) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned 128 bit integer to the underlying writer.
Source§

fn write_i128<T>(&mut self, n: i128) -> Result<(), Error>
where T: ByteOrder,

Writes a signed 128 bit integer to the underlying writer.
Source§

fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Source§

fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Source§

fn write_uint128<T>(&mut self, n: u128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes an unsigned n-bytes integer to the underlying writer. Read more
Source§

fn write_int128<T>(&mut self, n: i128, nbytes: usize) -> Result<(), Error>
where T: ByteOrder,

Writes a signed n-bytes integer to the underlying writer. Read more
Source§

fn write_f32<T>(&mut self, n: f32) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more
Source§

fn write_f64<T>(&mut self, n: f64) -> Result<(), Error>
where T: ByteOrder,

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more
Source§

impl<W> WriteEndian<[f32]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[f32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[f32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[f64]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[f64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[f64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[i128]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[i128]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[i128]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[i16]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[i16]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[i16]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[i32]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[i32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[i32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[i64]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[i64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[i64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[i8]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[i8]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[i8]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[u128]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[u128]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[u128]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[u16]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[u16]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[u16]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[u32]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[u32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[u32]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[u64]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[u64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[u64]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<[u8]> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &[u8]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &[u8]) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<f32> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &f32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &f32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<f64> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &f64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &f64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<i128> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &i128) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &i128) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<i16> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &i16) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &i16) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<i32> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &i32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &i32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<i64> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &i64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &i64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<i8> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &i8) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &i8) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<u128> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &u128) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &u128) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<u16> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &u16) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &u16) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<u32> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &u32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &u32) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<u64> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &u64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &u64) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<W> WriteEndian<u8> for W
where W: Write,

Source§

fn write_as_little_endian(&mut self, value: &u8) -> Result<(), Error>

Write the byte value of the specified reference, converting it to little endianness
Source§

fn write_as_big_endian(&mut self, value: &u8) -> Result<(), Error>

Write the byte value of the specified reference, converting it to big endianness
Source§

fn write_as_native_endian(&mut self, value: &T) -> Result<(), Error>

Write the byte value of the specified reference, not converting it
Source§

impl<T> Any for T
where T: Any,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,