feat: logging level configuration

This commit is contained in:
Aravinth Manivannan 2022-02-10 19:01:24 +05:30
parent 69b3ef7d59
commit 02c3264b82
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 23 additions and 5 deletions

View file

@ -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" },
]

View file

@ -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!(

View file

@ -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)
}
}