From 2475c36a758c5f6377ba5c49ced2805ac4287831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Mon, 25 Mar 2019 14:12:41 +0100 Subject: [PATCH] Implement log_level config option --- .env.template | 6 ++++++ src/config.rs | 2 ++ src/main.rs | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.env.template b/.env.template index 83a2f7fa..578d1e93 100644 --- a/.env.template +++ b/.env.template @@ -43,6 +43,12 @@ ## It's recommended to also set 'ROCKET_CLI_COLORS=off' # LOG_FILE=/path/to/log +## Log level +## Change the verbosity of the log output +## Valid values are "trace", "debug", "info", "warn", "error" and "off" +## This requires extended logging +# LOG_LEVEL=Info + ## Enable WAL for the DB ## Set to false to avoid enabling WAL during startup. ## Note that if the DB already has WAL enabled, you will also need to disable WAL in the DB, diff --git a/src/config.rs b/src/config.rs index 9ae5e6d0..77d64e4e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -277,6 +277,8 @@ make_config! { extended_logging: bool, false, def, true; /// Log file path log_file: String, false, option; + /// Log level + log_level: String, false, def, "Info".to_string(); /// Enable DB WAL |> Turning this off might lead to worse performance, but might help if using bitwarden_rs on some exotic filesystems, /// that do not support WAL. Please make sure you read project wiki on the topic before changing this setting. diff --git a/src/main.rs b/src/main.rs index 9e390a31..7d2d82b7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,7 @@ fn launch_info() { } fn init_logging() -> Result<(), fern::InitError> { + use std::str::FromStr; let mut logger = fern::Dispatch::new() .format(|out, message, record| { out.finish(format_args!( @@ -79,7 +80,7 @@ fn init_logging() -> Result<(), fern::InitError> { message )) }) - .level(log::LevelFilter::Info) + .level(log::LevelFilter::from_str(&CONFIG.log_level()).expect("Valid log level")) // Hide unknown certificate errors if using self-signed .level_for("rustls::session", log::LevelFilter::Off) // Hide failed to close stream messages