mirror of
https://github.com/dani-garcia/vaultwarden
synced 2024-09-30 22:48:58 +02:00
Allow to override log level for specific target
This commit is contained in:
parent
1e42755187
commit
8cb31fea43
3 changed files with 48 additions and 0 deletions
|
@ -366,6 +366,13 @@
|
||||||
## routes and static file, websocket and alive requests
|
## routes and static file, websocket and alive requests
|
||||||
# LOG_LEVEL=info
|
# LOG_LEVEL=info
|
||||||
|
|
||||||
|
## log level target override
|
||||||
|
## Change the verbosity of specific log output
|
||||||
|
## Format is a line for each "target=log_level"
|
||||||
|
#LOG_LEVEL_OVERRIDE="
|
||||||
|
#routes=warn
|
||||||
|
#"
|
||||||
|
|
||||||
## Token for the admin interface, preferably an Argon2 PCH string
|
## Token for the admin interface, preferably an Argon2 PCH string
|
||||||
## Vaultwarden has a built-in generator by calling `vaultwarden hash`
|
## Vaultwarden has a built-in generator by calling `vaultwarden hash`
|
||||||
## For details see: https://github.com/dani-garcia/vaultwarden/wiki/Enabling-admin-page#secure-the-admin_token
|
## For details see: https://github.com/dani-garcia/vaultwarden/wiki/Enabling-admin-page#secure-the-admin_token
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use std::env::consts::EXE_SUFFIX;
|
use std::env::consts::EXE_SUFFIX;
|
||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::sync::RwLock;
|
use std::sync::RwLock;
|
||||||
|
|
||||||
use job_scheduler_ng::Schedule;
|
use job_scheduler_ng::Schedule;
|
||||||
|
use log::LevelFilter;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use reqwest::Url;
|
use reqwest::Url;
|
||||||
|
|
||||||
|
@ -566,6 +568,8 @@ make_config! {
|
||||||
log_file: String, false, option;
|
log_file: String, false, option;
|
||||||
/// Log level
|
/// Log level
|
||||||
log_level: String, false, def, "Info".to_string();
|
log_level: String, false, def, "Info".to_string();
|
||||||
|
/// Override individual log level
|
||||||
|
log_level_override: String, false, def, String::new();
|
||||||
|
|
||||||
/// Enable DB WAL |> Turning this off might lead to worse performance, but might help if using vaultwarden on some exotic filesystems,
|
/// Enable DB WAL |> Turning this off might lead to worse performance, but might help if using vaultwarden on some exotic filesystems,
|
||||||
/// that do not support WAL. Please make sure you read project wiki on the topic before changing this setting.
|
/// that do not support WAL. Please make sure you read project wiki on the topic before changing this setting.
|
||||||
|
@ -1060,6 +1064,26 @@ fn smtp_convert_deprecated_ssl_options(smtp_ssl: Option<bool>, smtp_explicit_tls
|
||||||
"starttls".to_string()
|
"starttls".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allow to parse a multiline list of Key/Values (`key=value`)
|
||||||
|
/// Will ignore comment lines (starting with `//`)
|
||||||
|
fn parse_param_list(config: String) -> Vec<(String, String)> {
|
||||||
|
config
|
||||||
|
.lines()
|
||||||
|
.map(|l| l.trim())
|
||||||
|
.filter(|l| !l.is_empty() && !l.starts_with("//"))
|
||||||
|
.filter_map(|l| {
|
||||||
|
let split = l.split('=').collect::<Vec<&str>>();
|
||||||
|
match &split[..] {
|
||||||
|
[key, value] => Some(((*key).to_string(), (*value).to_string())),
|
||||||
|
_ => {
|
||||||
|
println!("[WARNING] Failed to parse ({l}). Expected key=value");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load() -> Result<Self, Error> {
|
pub fn load() -> Result<Self, Error> {
|
||||||
// Loading from env and file
|
// Loading from env and file
|
||||||
|
@ -1249,6 +1273,19 @@ impl Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn log_overrides(&self) -> Vec<(String, LevelFilter)> {
|
||||||
|
parse_param_list(self.log_level_override())
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|(k, v)| match LevelFilter::from_str(&v) {
|
||||||
|
Ok(lv) => Some((k, lv)),
|
||||||
|
Err(_) => {
|
||||||
|
println!("[WARNING] Invalid log level: {k}={v}");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use handlebars::{
|
use handlebars::{
|
||||||
|
|
|
@ -284,6 +284,10 @@ fn init_logging(level: log::LevelFilter) -> Result<(), fern::InitError> {
|
||||||
logger = logger.level_for("lettre::transport::smtp", log::LevelFilter::Off)
|
logger = logger.level_for("lettre::transport::smtp", log::LevelFilter::Off)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (path, level) in CONFIG.log_overrides() {
|
||||||
|
logger = logger.level_for(path, level);
|
||||||
|
}
|
||||||
|
|
||||||
if CONFIG.extended_logging() {
|
if CONFIG.extended_logging() {
|
||||||
logger = logger.format(|out, message, record| {
|
logger = logger.format(|out, message, record| {
|
||||||
out.finish(format_args!(
|
out.finish(format_args!(
|
||||||
|
|
Loading…
Reference in a new issue