mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 14:08:23 -05:00
Merge pull request #176 from neon-mmd/improve-logging-based-on-levels-and-opts
🔧 Config options to change the logging level with improved logging
This commit is contained in:
commit
58bc5789ca
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3534,7 +3534,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.16.1"
|
version = "0.16.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-cors",
|
"actix-cors",
|
||||||
"actix-files",
|
"actix-files",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "websurfx"
|
name = "websurfx"
|
||||||
version = "0.16.1"
|
version = "0.16.2"
|
||||||
edition = "2021"
|
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."
|
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"
|
repository = "https://github.com/neon-mmd/websurfx"
|
||||||
|
@ -24,8 +24,8 @@ async fn main() -> std::io::Result<()> {
|
|||||||
);
|
);
|
||||||
log::info!(
|
log::info!(
|
||||||
"Open http://{}:{}/ in your browser",
|
"Open http://{}:{}/ in your browser",
|
||||||
|
config.binding_ip,
|
||||||
config.port,
|
config.port,
|
||||||
config.binding_ip
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
|
let listener = TcpListener::bind((config.binding_ip.clone(), config.port))?;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use super::parser_models::Style;
|
use super::parser_models::Style;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use rlua::Lua;
|
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 --------
|
// ------- Constants --------
|
||||||
static COMMON_DIRECTORY_NAME: &str = "websurfx";
|
static COMMON_DIRECTORY_NAME: &str = "websurfx";
|
||||||
@ -79,26 +79,26 @@ impl Config {
|
|||||||
|
|
||||||
// Check whether logging has not been initialized before.
|
// Check whether logging has not been initialized before.
|
||||||
if logging_initialized {
|
if logging_initialized {
|
||||||
// Initializing logging middleware with level set to default or info.
|
if let Ok(pkg_env_var) = std::env::var("PKG_ENV"){
|
||||||
let mut log_level: LevelFilter = LevelFilter::Off;
|
if pkg_env_var.to_lowercase() == "dev" {
|
||||||
if logging && debug == false {
|
env_logger::Builder::new().filter(None, LevelFilter::Trace).init();
|
||||||
log_level = LevelFilter::Info;
|
}
|
||||||
} else if debug {
|
} else {
|
||||||
log_level = LevelFilter::Trace;
|
// Initializing logging middleware with level set to default or info.
|
||||||
};
|
let mut log_level: LevelFilter = LevelFilter::Error;
|
||||||
env_logger::Builder::new().filter(None, log_level).init();
|
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 threads: u8 = if parsed_threads == 0 {
|
||||||
let total_num_of_threads:usize = available_parallelism()?.get() /2;
|
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::error!("Config Error: The value of `threads` option should be a non zero positive integer");
|
log::error!("Falling back to using {} threads", total_num_of_threads);
|
||||||
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())?;
|
|
||||||
};
|
|
||||||
total_num_of_threads as u8
|
total_num_of_threads as u8
|
||||||
} else {
|
} else {
|
||||||
parsed_threads
|
parsed_threads
|
||||||
|
@ -144,6 +144,7 @@ pub async fn aggregate(
|
|||||||
initial = false
|
initial = false
|
||||||
}
|
}
|
||||||
Err(error_type) => {
|
Err(error_type) => {
|
||||||
|
log::error!("Engine Error: {:?}", error_type);
|
||||||
engine_errors_info.push(EngineErrorInfo::new(
|
engine_errors_info.push(EngineErrorInfo::new(
|
||||||
error_type.downcast_ref::<EngineError>().unwrap(),
|
error_type.downcast_ref::<EngineError>().unwrap(),
|
||||||
upstream_search_engines[counter].clone(),
|
upstream_search_engines[counter].clone(),
|
||||||
@ -172,6 +173,7 @@ pub async fn aggregate(
|
|||||||
counter += 1
|
counter += 1
|
||||||
}
|
}
|
||||||
Err(error_type) => {
|
Err(error_type) => {
|
||||||
|
log::error!("Engine Error: {:?}", error_type);
|
||||||
engine_errors_info.push(EngineErrorInfo::new(
|
engine_errors_info.push(EngineErrorInfo::new(
|
||||||
error_type.downcast_ref::<EngineError>().unwrap(),
|
error_type.downcast_ref::<EngineError>().unwrap(),
|
||||||
upstream_search_engines[counter].clone(),
|
upstream_search_engines[counter].clone(),
|
||||||
|
Loading…
Reference in New Issue
Block a user