Added another init method for logger
This commit is contained in:
parent
a8395da5c9
commit
916c82debc
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -183,7 +183,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-web-utils"
|
name = "actix-web-utils"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"log",
|
"log",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "actix-web-utils"
|
name = "actix-web-utils"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Franklin E. Blanco"]
|
authors = ["Franklin E. Blanco"]
|
||||||
description = "Just some useful addons for actix web."
|
description = "Just some useful addons for actix web."
|
||||||
|
@ -4,7 +4,22 @@ use crate::extensions::logger::SimpleLogger;
|
|||||||
|
|
||||||
static LOGGER: SimpleLogger = SimpleLogger;
|
static LOGGER: SimpleLogger = SimpleLogger;
|
||||||
|
|
||||||
pub fn init(max_log_level_filter: LevelFilter) -> Result<(), SetLoggerError> {
|
pub fn init_logger_default() -> Result<(), SetLoggerError> {
|
||||||
log::set_logger(&LOGGER)
|
log::set_logger(&LOGGER)
|
||||||
.map(|()| log::set_max_level(max_log_level_filter))
|
.map(|()| log::set_max_level(LevelFilter::Info))
|
||||||
|
}
|
||||||
|
/// Made this get an integer so that you don't have to import the Log library in your code too, as the LevelFilter enum is inside it.
|
||||||
|
/// 0 -> Off, 1 -> Trace, 2 -> Debug, 3 -> Info, 4 -> Warn, 5 -> Error
|
||||||
|
pub fn init_logger_custom(max_log_level_filter: i8) -> Result<(), SetLoggerError> {
|
||||||
|
let level_filter: LevelFilter = match max_log_level_filter {
|
||||||
|
0 => LevelFilter::Off,
|
||||||
|
1 => LevelFilter::Trace,
|
||||||
|
2 => LevelFilter::Debug,
|
||||||
|
3 => LevelFilter::Info,
|
||||||
|
4 => LevelFilter::Warn,
|
||||||
|
5 => LevelFilter::Error,
|
||||||
|
_ => panic!("INVALID max_log_level_filter. Only values between 0-5 are allowed."),
|
||||||
|
};
|
||||||
|
log::set_logger(&LOGGER)
|
||||||
|
.map(|()| log::set_max_level(level_filter))
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user