eris: allow various log formats
Supports plain, pretty, json and pretty-json
This commit is contained in:
parent
66993ebdec
commit
9297ba4e0c
2 changed files with 93 additions and 6 deletions
|
@ -85,6 +85,22 @@ pub struct Args {
|
|||
help = "Log level: trace, debug, info, warn, error"
|
||||
)]
|
||||
pub log_level: String,
|
||||
|
||||
#[clap(
|
||||
long,
|
||||
default_value = "pretty",
|
||||
help = "Log format: plain, pretty, json, pretty-json"
|
||||
)]
|
||||
pub log_format: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
|
||||
pub enum LogFormat {
|
||||
Plain,
|
||||
#[default]
|
||||
Pretty,
|
||||
Json,
|
||||
PrettyJson,
|
||||
}
|
||||
|
||||
// Trap pattern structure. It can be either a plain string
|
||||
|
@ -145,6 +161,7 @@ pub struct Config {
|
|||
pub data_dir: String,
|
||||
pub config_dir: String,
|
||||
pub cache_dir: String,
|
||||
pub log_format: LogFormat,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -206,6 +223,7 @@ impl Default for Config {
|
|||
data_dir: "./data".to_string(),
|
||||
config_dir: "./conf".to_string(),
|
||||
cache_dir: "./cache".to_string(),
|
||||
log_format: LogFormat::Pretty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,6 +424,7 @@ mod tests {
|
|||
base_dir: Some(PathBuf::from("/tmp/eris")),
|
||||
config_file: None,
|
||||
log_level: "debug".to_string(),
|
||||
log_format: "pretty".to_string(),
|
||||
};
|
||||
|
||||
let config = Config::from_args(&args);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue