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
impl Logger
Sourcepub fn from_env<'a, E>(env: E) -> Logger
pub fn from_env<'a, E>(env: E) -> Logger
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);
Sourcepub fn from_default_env() -> Logger
pub fn from_default_env() -> Logger
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();
Sourcepub fn filter(&self) -> LevelFilter
pub fn filter(&self) -> LevelFilter
Returns the maximum LevelFilter
that this env logger instance is
configured to output.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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