XFFXFF commited on
Commit
58bc578
2 Parent(s): a5b7d08 ca13fb7

Merge pull request #176 from neon-mmd/improve-logging-based-on-levels-and-opts

Browse files
Cargo.lock CHANGED
@@ -3534,7 +3534,7 @@ dependencies = [
3534
 
3535
  [[package]]
3536
  name = "websurfx"
3537
- version = "0.16.1"
3538
  dependencies = [
3539
  "actix-cors",
3540
  "actix-files",
 
3534
 
3535
  [[package]]
3536
  name = "websurfx"
3537
+ version = "0.16.2"
3538
  dependencies = [
3539
  "actix-cors",
3540
  "actix-files",
Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
  [package]
2
  name = "websurfx"
3
- version = "0.16.1"
4
  edition = "2021"
5
  description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
6
  repository = "https://github.com/neon-mmd/websurfx"
 
1
  [package]
2
  name = "websurfx"
3
+ version = "0.16.2"
4
  edition = "2021"
5
  description = "An open-source alternative to Searx that provides clean, ad-free, and organic results with incredible speed while keeping privacy and security in mind."
6
  repository = "https://github.com/neon-mmd/websurfx"
src/bin/websurfx.rs CHANGED
@@ -24,8 +24,8 @@ async fn main() -> std::io::Result<()> {
24
  );
25
  log::info!(
26
  "Open http://{}:{}/ in your browser",
 
27
  config.port,
28
- config.binding_ip
29
  );
30
 
31
  let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
 
24
  );
25
  log::info!(
26
  "Open http://{}:{}/ in your browser",
27
+ config.binding_ip,
28
  config.port,
 
29
  );
30
 
31
  let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
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, io::Write, path::Path, thread::available_parallelism};
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
- // Initializing logging middleware with level set to default or info.
83
- let mut log_level: LevelFilter = LevelFilter::Off;
84
- if logging && debug == false {
85
- log_level = LevelFilter::Info;
86
- } else if debug {
87
- log_level = LevelFilter::Trace;
88
- };
89
- env_logger::Builder::new().filter(None, log_level).init();
 
 
 
 
 
 
90
  }
91
 
92
  let threads: u8 = if parsed_threads == 0 {
93
- let total_num_of_threads:usize = available_parallelism()?.get() /2;
94
- if debug || logging {
95
- log::error!("Config Error: The value of `threads` option should be a non zero positive integer");
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::error!("Falling back to using {} threads", total_num_of_threads);
 
 
 
 
 
 
102
  total_num_of_threads as u8
103
  } else {
104
  parsed_threads
src/results/aggregator.rs CHANGED
@@ -144,6 +144,7 @@ pub async fn aggregate(
144
  initial = false
145
  }
146
  Err(error_type) => {
 
147
  engine_errors_info.push(EngineErrorInfo::new(
148
  error_type.downcast_ref::<EngineError>().unwrap(),
149
  upstream_search_engines[counter].clone(),
@@ -172,6 +173,7 @@ pub async fn aggregate(
172
  counter += 1
173
  }
174
  Err(error_type) => {
 
175
  engine_errors_info.push(EngineErrorInfo::new(
176
  error_type.downcast_ref::<EngineError>().unwrap(),
177
  upstream_search_engines[counter].clone(),
 
144
  initial = false
145
  }
146
  Err(error_type) => {
147
+ log::error!("Engine Error: {:?}", error_type);
148
  engine_errors_info.push(EngineErrorInfo::new(
149
  error_type.downcast_ref::<EngineError>().unwrap(),
150
  upstream_search_engines[counter].clone(),
 
173
  counter += 1
174
  }
175
  Err(error_type) => {
176
+ log::error!("Engine Error: {:?}", error_type);
177
  engine_errors_info.push(EngineErrorInfo::new(
178
  error_type.downcast_ref::<EngineError>().unwrap(),
179
  upstream_search_engines[counter].clone(),