diff --git a/config/default.toml b/config/default.toml index b68eb79..1c2c818 100644 --- a/config/default.toml +++ b/config/default.toml @@ -1,6 +1,5 @@ -debug = true +log = "info" # possible values: "info", "warn", "trace", "error", "debug" source_code = "https://github.com/realaravinth/pages" - pages = [ { branch = "gh-pages", repo = "https://github.com/mCaptcha/website/", path ="/tmp/pages/mcaptcha/website", secret = "faee1b650ac586068a54cb160bd6353c5e16be7c64b49113fe57726e5393" }, ] diff --git a/src/main.rs b/src/main.rs index 69cb0a5..1d50ac0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,8 +47,7 @@ pub const PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE"); #[cfg(not(tarpaulin_include))] #[actix_web::main] async fn main() -> std::io::Result<()> { - env::set_var("RUST_LOG", "info"); - + lazy_static::initialize(&SETTINGS); pretty_env_logger::init(); info!( diff --git a/src/settings.rs b/src/settings.rs index b884c81..2572ae0 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -18,6 +18,7 @@ use std::env; use std::path::Path; use config::{Config, ConfigError, Environment, File}; +use derive_more::Display; use log::warn; use serde::Deserialize; use url::Url; @@ -40,9 +41,24 @@ impl Server { } } +#[derive(Deserialize, Display, Clone, Debug)] +#[serde(rename_all = "lowercase")] +pub enum LogLevel { + #[display(fmt = "debug")] + Debug, + #[display(fmt = "info")] + Info, + #[display(fmt = "trace")] + Trace, + #[display(fmt = "error")] + Error, + #[display(fmt = "warn")] + Warn, +} + #[derive(Debug, Clone, Deserialize)] pub struct Settings { - pub debug: bool, + pub log: LogLevel, // pub database: Database, pub server: Server, pub source_code: String, @@ -108,6 +124,10 @@ impl Settings { page.fetch_upstream(&page.branch); } + const LOG_VAR: &str = "RUST_LOG"; + if env::var(LOG_VAR).is_err() { + env::set_var("RUST_LOG", format!("{}", settings.log)); + } Ok(settings) } }