From 8b0f2f50f0f0b59d9aa3511ef8339ae1e6807065 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Thu, 3 Aug 2023 23:09:08 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20chore:=20improve=20logging?= =?UTF-8?q?=20based=20on=20levels=20&=20config=20options=20(#173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/parser.rs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/config/parser.rs b/src/config/parser.rs index 51a83ea..33421b0 100644 --- a/src/config/parser.rs +++ b/src/config/parser.rs @@ -4,7 +4,7 @@ use super::parser_models::Style; use log::LevelFilter; use rlua::Lua; -use std::{collections::HashMap, format, fs, io::Write, path::Path, thread::available_parallelism}; +use std::{collections::HashMap, format, fs, path::Path, thread::available_parallelism}; // ------- Constants -------- static COMMON_DIRECTORY_NAME: &str = "websurfx"; @@ -79,26 +79,26 @@ impl Config { // Check whether logging has not been initialized before. if logging_initialized { - // Initializing logging middleware with level set to default or info. - let mut log_level: LevelFilter = LevelFilter::Off; - if logging && debug == false { - log_level = LevelFilter::Info; - } else if debug { - log_level = LevelFilter::Trace; - }; - env_logger::Builder::new().filter(None, log_level).init(); + 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(); + } } let threads: u8 = if parsed_threads == 0 { - let total_num_of_threads:usize = available_parallelism()?.get() /2; - if debug || logging { - log::error!("Config Error: The value of `threads` option should be a non zero positive integer"); - log::info!("Falling back to using {} threads", total_num_of_threads) - } else { - std::io::stdout() - .lock() - .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())?; - }; + let total_num_of_threads: usize = available_parallelism()?.get() / 2; + log::error!("Config Error: The value of `threads` option should be a non zero positive integer"); + log::info!("Falling back to using {} threads", total_num_of_threads); total_num_of_threads as u8 } else { parsed_threads From 246d043e4a168845b96d7acd9a95236eca1a486e Mon Sep 17 00:00:00 2001 From: neon_arch Date: Thu, 3 Aug 2023 23:11:49 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=9A=80=20chore:=20bump=20the=20app=20?= =?UTF-8?q?version=20(#173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 14 +++++++------- Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98a6247..3138dfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -190,7 +190,7 @@ dependencies = [ "serde_urlencoded 0.7.1", "smallvec 1.11.0", "socket2", - "time 0.3.24", + "time 0.3.25", "url 2.4.0", ] @@ -583,7 +583,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" dependencies = [ "percent-encoding 2.3.0", - "time 0.3.24", + "time 0.3.25", "version_check", ] @@ -801,9 +801,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8810e7e2cf385b1e9b50d68264908ec367ba642c96d02edfe61c39e88e2a3c01" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" [[package]] name = "derive_more" @@ -3000,9 +3000,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.24" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79eabcd964882a646b3584543ccabeae7869e9ac32a46f6f22b7a5bd405308b" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" dependencies = [ "deranged", "itoa 1.0.9", @@ -3519,7 +3519,7 @@ dependencies = [ [[package]] name = "websurfx" -version = "0.16.0" +version = "0.16.2" dependencies = [ "actix-files", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index ec8d159..68398fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "websurfx" -version = "0.16.0" +version = "0.16.2" edition = "2021" 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." repository = "https://github.com/neon-mmd/websurfx" From 653d08c80167477f4011cdb157af9ecbaeb1504a Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 5 Aug 2023 19:16:27 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A7=20chore:=20fix=20link=20in=20t?= =?UTF-8?q?he=20logs=20&=20add=20logs=20for=20engine=20error=20(#170)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/websurfx.rs | 2 +- src/config/parser.rs | 2 +- src/results/aggregator.rs | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/websurfx.rs b/src/bin/websurfx.rs index b4b989e..6807749 100644 --- a/src/bin/websurfx.rs +++ b/src/bin/websurfx.rs @@ -24,8 +24,8 @@ async fn main() -> std::io::Result<()> { ); log::info!( "Open http://{}:{}/ in your browser", + config.binding_ip, config.port, - config.binding_ip ); let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?; diff --git a/src/config/parser.rs b/src/config/parser.rs index 33421b0..201e579 100644 --- a/src/config/parser.rs +++ b/src/config/parser.rs @@ -98,7 +98,7 @@ impl Config { let threads: u8 = if parsed_threads == 0 { let total_num_of_threads: usize = available_parallelism()?.get() / 2; log::error!("Config Error: The value of `threads` option should be a non zero positive integer"); - log::info!("Falling back to using {} threads", total_num_of_threads); + log::error!("Falling back to using {} threads", total_num_of_threads); total_num_of_threads as u8 } else { parsed_threads diff --git a/src/results/aggregator.rs b/src/results/aggregator.rs index b8d7346..4ffaaf5 100644 --- a/src/results/aggregator.rs +++ b/src/results/aggregator.rs @@ -144,6 +144,7 @@ pub async fn aggregate( initial = false } Err(error_type) => { + log::error!("Engine Error: {:?}", error_type); engine_errors_info.push(EngineErrorInfo::new( error_type.downcast_ref::().unwrap(), upstream_search_engines[counter].clone(), @@ -172,6 +173,7 @@ pub async fn aggregate( counter += 1 } Err(error_type) => { + log::error!("Engine Error: {:?}", error_type); engine_errors_info.push(EngineErrorInfo::new( error_type.downcast_ref::().unwrap(), upstream_search_engines[counter].clone(),