log level as cmd argument

This commit is contained in:
jb-alvarado 2023-07-24 20:30:31 +02:00
parent 72b390aba9
commit 334f842d19
3 changed files with 21 additions and 6 deletions

View File

@ -95,7 +95,8 @@ playlist:
infinit: false
storage:
help_text: 'filler' is for playing instead of a missing file or fill the end to reach 24
help_text: >
'filler' is for playing instead of a missing file or fill the end to reach 24
hours, can be a file or folder, it will loop when is necessary. 'extensions' search
only files with this extension. Set 'shuffle' to 'true' to pick files randomly.
path: "/var/lib/ffplayout/tv-media"

View File

@ -14,7 +14,8 @@ pub use arg_parse::Args;
use ffplayout_lib::{
filter::Filters,
utils::{
get_sec, sec_to_time, time_to_sec, Media, OutputMode::*, PlayoutConfig, ProcessMode::*,
get_sec, parse_log_level_filter, sec_to_time, time_to_sec, Media, OutputMode::*,
PlayoutConfig, ProcessMode::*,
},
vec_strings,
};
@ -86,10 +87,11 @@ pub fn get_config(args: Args) -> PlayoutConfig {
}
}
// TODO: implement this
// if let Some(level) = args.level {
// config.logging.level = LevelFilter::from(level);
// }
if let Some(level) = args.level {
if let Ok(filter) = parse_log_level_filter(&level) {
config.logging.level = filter;
}
}
if args.infinit {
config.playlist.infinit = args.infinit;

View File

@ -883,6 +883,18 @@ pub fn get_date_range(date_range: &[String]) -> Vec<String> {
range
}
pub fn parse_log_level_filter(s: &str) -> Result<LevelFilter, &'static str> {
match s.to_lowercase().as_str() {
"debug" => Ok(LevelFilter::Debug),
"error" => Ok(LevelFilter::Error),
"info" => Ok(LevelFilter::Info),
"trace" => Ok(LevelFilter::Trace),
"warning" => Ok(LevelFilter::Warn),
"off" => Ok(LevelFilter::Off),
_ => Err("Error level not exists!"),
}
}
pub fn home_dir() -> Option<PathBuf> {
home_dir_inner()
}