Struct env_logger::Logger

source ·
pub struct Logger { /* private fields */ }
Expand description

The env logger.

This struct implements the Log trait from the log crate, which allows it to act as a logger.

The init(), try_init(), Builder::init() and Builder::try_init() methods will each construct a Logger and immediately initialize it as the default global logger.

If you’d instead need access to the constructed Logger, you can use the associated Builder and install it with the log crate directly.

Implementations§

source§

impl Logger

source

pub fn from_env<'a, E>(env: E) -> Self
where E: Into<Env<'a>>,

Creates the logger from the environment.

The variables used to read configuration from can be tweaked before passing in.

§Examples

Create a logger reading the log filter from an environment variable called MY_LOG:

use env_logger::Logger;

let logger = Logger::from_env("MY_LOG");

Create a logger using the MY_LOG variable for filtering and MY_LOG_STYLE for whether or not to write styles:

use env_logger::{Logger, Env};

let env = Env::new().filter_or("MY_LOG", "info").write_style_or("MY_LOG_STYLE", "always");

let logger = Logger::from_env(env);
source

pub fn from_default_env() -> Self

Creates the logger from the environment using default variable names.

This method is a convenient way to call from_env(Env::default()) without having to use the Env type explicitly. The logger will use the default environment variables.

§Examples

Creates a logger using the default environment variables:

use env_logger::Logger;

let logger = Logger::from_default_env();
source

pub fn filter(&self) -> LevelFilter

Returns the maximum LevelFilter that this env logger instance is configured to output.

source

pub fn matches(&self, record: &Record<'_>) -> bool

Checks if this record matches the configured filter.

Trait Implementations§

source§

impl Debug for Logger

source§

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

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

impl Log for Logger

source§

fn enabled(&self, metadata: &Metadata<'_>) -> bool

Determines if a log message with the specified metadata would be logged. Read more
source§

fn log(&self, record: &Record<'_>)

Logs the Record. Read more
source§

fn flush(&self)

Flushes any buffered records. Read more

Auto Trait Implementations§

§

impl !Freeze for Logger

§

impl !RefUnwindSafe for Logger

§

impl Send for Logger

§

impl Sync for Logger

§

impl Unpin for Logger

§

impl !UnwindSafe for Logger

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.