[][src]Struct simple_logger::SimpleLogger

pub struct SimpleLogger { /* fields omitted */ }

Implementations

impl SimpleLogger[src]

#[must_use = "You must call init() to begin logging"]pub fn new() -> SimpleLogger[src]

Initializes the global logger with a SimpleLogger instance with default log level set to Level::Trace.

You may use the various builder-style methods on this type to configure the logger, and you must call init in order to start logging messages.

use simple_logger::SimpleLogger;
SimpleLogger::new().init().unwrap();
log::warn!("This is an example message.");

#[must_use = "You must call init() to begin logging"]pub fn from_env() -> SimpleLogger[src]

A macro for simulating env_logger behavior, which enables the user to choose log level by setting a RUST_LOG environment variable. The RUST_LOG is not set or its value is not recognized as one of the log levels, this function with use the Error level by default.

You may use the various builder-style methods on this type to configure the logger, and you must call init in order to start logging messages.

use simple_logger::SimpleLogger;
SimpleLogger::from_env().init().unwrap();
log::warn!("This is an example message.");

#[must_use = "You must call init() to begin logging"]pub fn with_level(self, level: LevelFilter) -> SimpleLogger[src]

Set the 'default' log level.

You can override the default level for specific modules and their sub-modules using with_module_level

#[must_use = "You must call init() to begin logging"]pub fn with_module_level(self, target: &str, level: LevelFilter) -> SimpleLogger[src]

Override the log level for some specific modules.

This sets the log level of a specific module and all its sub-modules. When both the level for a parent module as well as a child module are set, the more specific value is taken. If the log level for the same module is specified twice, the resulting log level is implementation defined.

Examples

Silence an overly verbose crate:

use simple_logger::SimpleLogger;
use log::LevelFilter;

SimpleLogger::new().with_module_level("chatty_dependency", LevelFilter::Warn).init().unwrap();

Disable logging for all dependencies:

use simple_logger::SimpleLogger;
use log::LevelFilter;

SimpleLogger::new()
    .with_level(LevelFilter::Off)
    .with_module_level("my_crate", LevelFilter::Info)
    .init()
    .unwrap();

#[must_use = "You must call init() to begin logging"]pub fn with_target_levels(
    self,
    target_levels: HashMap<String, LevelFilter>
) -> SimpleLogger
[src]

👎 Deprecated since 1.11.0:

This is a leftover from before there was the builder pattern. Use with_module_level instead.

Override the log level for specific targets.

pub fn init(self) -> Result<(), SetLoggerError>[src]

'Init' the actual logger, instantiate it and configure it, this method MUST be called in order for the logger to be effective.

Trait Implementations

impl Default for SimpleLogger[src]

fn default() -> Self[src]

See this

impl Log for SimpleLogger[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.