neon_arch
commited on
Commit
Β·
8b0f2f5
1
Parent(s):
e02fafd
π§ chore: improve logging based on levels & config options (#173)
Browse files- src/config/parser.rs +18 -18
src/config/parser.rs
CHANGED
@@ -4,7 +4,7 @@
|
|
4 |
use super::parser_models::Style;
|
5 |
use log::LevelFilter;
|
6 |
use rlua::Lua;
|
7 |
-
use std::{collections::HashMap, format, fs,
|
8 |
|
9 |
// ------- Constants --------
|
10 |
static COMMON_DIRECTORY_NAME: &str = "websurfx";
|
@@ -79,26 +79,26 @@ impl Config {
|
|
79 |
|
80 |
// Check whether logging has not been initialized before.
|
81 |
if logging_initialized {
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
} else
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
}
|
91 |
|
92 |
let threads: u8 = if parsed_threads == 0 {
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
log::info!("Falling back to using {} threads", total_num_of_threads)
|
97 |
-
} else {
|
98 |
-
std::io::stdout()
|
99 |
-
.lock()
|
100 |
-
.write_all(&format!("Config Error: The value of `threads` option should be a non zero positive integer\nFalling back to using {} threads\n", total_num_of_threads).into_bytes())?;
|
101 |
-
};
|
102 |
total_num_of_threads as u8
|
103 |
} else {
|
104 |
parsed_threads
|
|
|
4 |
use super::parser_models::Style;
|
5 |
use log::LevelFilter;
|
6 |
use rlua::Lua;
|
7 |
+
use std::{collections::HashMap, format, fs, path::Path, thread::available_parallelism};
|
8 |
|
9 |
// ------- Constants --------
|
10 |
static COMMON_DIRECTORY_NAME: &str = "websurfx";
|
|
|
79 |
|
80 |
// Check whether logging has not been initialized before.
|
81 |
if logging_initialized {
|
82 |
+
if let Ok(pkg_env_var) = std::env::var("PKG_ENV"){
|
83 |
+
if pkg_env_var.to_lowercase() == "dev" {
|
84 |
+
env_logger::Builder::new().filter(None, LevelFilter::Trace).init();
|
85 |
+
}
|
86 |
+
} else {
|
87 |
+
// Initializing logging middleware with level set to default or info.
|
88 |
+
let mut log_level: LevelFilter = LevelFilter::Error;
|
89 |
+
if logging && debug == false {
|
90 |
+
log_level = LevelFilter::Info;
|
91 |
+
} else if debug {
|
92 |
+
log_level = LevelFilter::Debug;
|
93 |
+
};
|
94 |
+
env_logger::Builder::new().filter(None, log_level).init();
|
95 |
+
}
|
96 |
}
|
97 |
|
98 |
let threads: u8 = if parsed_threads == 0 {
|
99 |
+
let total_num_of_threads: usize = available_parallelism()?.get() / 2;
|
100 |
+
log::error!("Config Error: The value of `threads` option should be a non zero positive integer");
|
101 |
+
log::info!("Falling back to using {} threads", total_num_of_threads);
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
total_num_of_threads as u8
|
103 |
} else {
|
104 |
parsed_threads
|