Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Simple Logger set the level manually

Using the init_with_level function we can set the log level manually.

[package]
name = "simple_logger_init_with_level"
version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.22"
simple_logger = "5.0.0"
fn main() {
    simple_logger::init_with_level(log::Level::Info).unwrap();

    log::trace!("This is a sample trace.");
    log::debug!("This is a sample debug.");
    log::info!("This is a sample info.");
    log::warn!("This is a sample warn.");
    log::error!("This is a sample error.");
}
2024-08-04T12:12:25.438Z INFO  [simple_logger_init_with_level] This is a sample info.
2024-08-04T12:12:25.438Z WARN  [simple_logger_init_with_level] This is a sample warn.
2024-08-04T12:12:25.438Z ERROR [simple_logger_init_with_level] This is a sample error.