Improve Aggregation function & config parser
Refactor aggregation function Rename visiting_url to url, as they are always the same (see upstream engine scalping). Refactor parsing function to be more readable.
This commit is contained in:
parent
af3b1cb308
commit
15dfda6ea9
8 changed files with 103 additions and 136 deletions
|
@ -57,7 +57,7 @@ impl Config {
|
|||
/// # Arguments
|
||||
///
|
||||
/// * `logging_initialized` - It takes a boolean which ensures that the logging doesn't get
|
||||
/// initialized twice.
|
||||
/// initialized twice. Pass false if the logger has not yet been initialized.
|
||||
///
|
||||
/// # Error
|
||||
///
|
||||
|
@ -76,23 +76,9 @@ impl Config {
|
|||
|
||||
let debug: bool = globals.get::<_, bool>("debug")?;
|
||||
let logging:bool= globals.get::<_, bool>("logging")?;
|
||||
|
||||
// Check whether logging has not been initialized before.
|
||||
if logging_initialized {
|
||||
if let Ok(pkg_env_var) = std::env::var("PKG_ENV"){
|
||||
if pkg_env_var.to_lowercase() == "dev" {
|
||||
env_logger::Builder::new().filter(None, LevelFilter::Trace).init();
|
||||
}
|
||||
} else {
|
||||
// Initializing logging middleware with level set to default or info.
|
||||
let mut log_level: LevelFilter = LevelFilter::Error;
|
||||
if logging && debug == false {
|
||||
log_level = LevelFilter::Info;
|
||||
} else if debug {
|
||||
log_level = LevelFilter::Debug;
|
||||
};
|
||||
env_logger::Builder::new().filter(None, log_level).init();
|
||||
}
|
||||
|
||||
if !logging_initialized {
|
||||
set_logging_level(debug, logging);
|
||||
}
|
||||
|
||||
let threads: u8 = if parsed_threads == 0 {
|
||||
|
@ -127,6 +113,7 @@ impl Config {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// A helper function which returns an appropriate config file path checking if the config
|
||||
/// file exists on that path.
|
||||
///
|
||||
|
@ -173,3 +160,26 @@ impl Config {
|
|||
Err("Config file not found!!".to_string().into())
|
||||
}
|
||||
}
|
||||
|
||||
/// a helper function that sets the proper logging level
|
||||
fn set_logging_level(debug: bool, logging: bool) {
|
||||
|
||||
if let Ok(pkg_env_var) = std::env::var("PKG_ENV") {
|
||||
if pkg_env_var.to_lowercase() == "dev" {
|
||||
env_logger::Builder::new()
|
||||
.filter(None, LevelFilter::Trace)
|
||||
.init();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Initializing logging middleware with level set to default or info.
|
||||
let log_level = match (debug, logging) {
|
||||
(true, true) => LevelFilter::Error,
|
||||
(true, false) => LevelFilter::Debug,
|
||||
(false, true) => LevelFilter::Info,
|
||||
(false, false) => LevelFilter::Error,
|
||||
};
|
||||
|
||||
env_logger::Builder::new().filter(None, log_level).init();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue