mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 22:18:23 -05:00
Compare commits
2 Commits
15aaa1b63f
...
c73b7bea77
Author | SHA1 | Date | |
---|---|---|---|
|
c73b7bea77 | ||
|
0a0508de80 |
@ -4,7 +4,7 @@
|
|||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
|
||||||
use crate::config::{process_settings, Config};
|
use crate::config::{process_settings, set_logging_level, Config};
|
||||||
use crate::handler::{file_path, FileType};
|
use crate::handler::{file_path, FileType};
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -20,11 +20,7 @@ impl Config {
|
|||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
log::error!("Config Error: No config file found, falling back to defaults");
|
log::error!("Config Error: No config file found, falling back to defaults");
|
||||||
let conf = Self::default();
|
return Ok(Self::default());
|
||||||
if !logging_initialized {
|
|
||||||
conf.set_logging_level();
|
|
||||||
}
|
|
||||||
return Ok(conf);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -33,7 +29,7 @@ impl Config {
|
|||||||
let mut conf: Config = serde_json::from_reader(reader)?;
|
let mut conf: Config = serde_json::from_reader(reader)?;
|
||||||
|
|
||||||
if !logging_initialized {
|
if !logging_initialized {
|
||||||
conf.set_logging_level();
|
set_logging_level(conf.server.debug, conf.server.logging)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = process_settings(conf)?;
|
conf = process_settings(conf)?;
|
||||||
|
@ -4,7 +4,7 @@ use std::fs;
|
|||||||
|
|
||||||
use mlua::{Lua, LuaSerdeExt};
|
use mlua::{Lua, LuaSerdeExt};
|
||||||
|
|
||||||
use crate::config::{process_settings, Config};
|
use crate::config::{process_settings, set_logging_level, Config};
|
||||||
use crate::handler::{file_path, FileType};
|
use crate::handler::{file_path, FileType};
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -21,11 +21,7 @@ impl Config {
|
|||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
log::error!("Config Error: No config file found, falling back to defaults");
|
log::error!("Config Error: No config file found, falling back to defaults");
|
||||||
let conf = Self::default();
|
return Ok(Self::default());
|
||||||
if !logging_initialized {
|
|
||||||
conf.set_logging_level();
|
|
||||||
}
|
|
||||||
return Ok(conf);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let val = lua.load(fs::read_to_string(config_file)?).eval()?;
|
let val = lua.load(fs::read_to_string(config_file)?).eval()?;
|
||||||
@ -33,7 +29,7 @@ impl Config {
|
|||||||
let mut conf: Config = lua.from_value(val)?;
|
let mut conf: Config = lua.from_value(val)?;
|
||||||
|
|
||||||
if !logging_initialized {
|
if !logging_initialized {
|
||||||
conf.set_logging_level();
|
set_logging_level(conf.server.debug, conf.server.logging)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = process_settings(conf)?;
|
conf = process_settings(conf)?;
|
||||||
|
@ -20,9 +20,13 @@ pub struct Config {
|
|||||||
pub search: Search,
|
pub search: Search,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
|
||||||
/// a helper function that sets the proper logging level
|
/// a helper function that sets the proper logging level
|
||||||
fn set_logging_level(&self) {
|
///
|
||||||
|
/// # Arguments
|
||||||
|
///
|
||||||
|
/// * `debug` - It takes the option to whether enable or disable debug mode.
|
||||||
|
/// * `logging` - It takes the option to whether enable or disable logs.
|
||||||
|
fn set_logging_level(debug: bool, logging: bool) {
|
||||||
if let Ok(pkg_env_var) = std::env::var("PKG_ENV") {
|
if let Ok(pkg_env_var) = std::env::var("PKG_ENV") {
|
||||||
if pkg_env_var.to_lowercase() == "dev" {
|
if pkg_env_var.to_lowercase() == "dev" {
|
||||||
env_logger::Builder::new()
|
env_logger::Builder::new()
|
||||||
@ -33,7 +37,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initializing logging middleware with level set to default or info.
|
// Initializing logging middleware with level set to default or info.
|
||||||
let log_level = match (self.server.debug, self.server.logging) {
|
let log_level = match (debug, logging) {
|
||||||
(true, true) => LevelFilter::Debug,
|
(true, true) => LevelFilter::Debug,
|
||||||
(true, false) => LevelFilter::Debug,
|
(true, false) => LevelFilter::Debug,
|
||||||
(false, true) => LevelFilter::Info,
|
(false, true) => LevelFilter::Info,
|
||||||
@ -42,7 +46,6 @@ impl Config {
|
|||||||
|
|
||||||
env_logger::Builder::new().filter(None, log_level).init();
|
env_logger::Builder::new().filter(None, log_level).init();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn process_settings(mut conf: Config) -> Result<Config, Box<dyn std::error::Error>> {
|
fn process_settings(mut conf: Config) -> Result<Config, Box<dyn std::error::Error>> {
|
||||||
conf.search.safe_search = match conf.search.safe_search {
|
conf.search.safe_search = match conf.search.safe_search {
|
||||||
|
Loading…
Reference in New Issue
Block a user