From c38971fd788cddb9885ab643ade06e7b4ca3b9c9 Mon Sep 17 00:00:00 2001 From: rasul Date: Wed, 6 Nov 2019 06:18:18 -0600 Subject: [PATCH] config options for stdout and stderr logs --- src/config.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/config.rs b/src/config.rs index 3d3b3a9..29794fa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,8 @@ use log::LevelFilter; pub struct Config { pub config_directory: PathBuf, pub log_level: LevelFilter, + pub stdout: PathBuf, + pub stderr: PathBuf, } impl Config { @@ -24,6 +26,8 @@ impl Config { "log level (error, warn, info, debug, trace)", "LEVEL", ); + opts.optopt("o", "out", "stdout path", "STDOUT"); + opts.optopt("e", "err", "stderr path", "STDERR"); opts.optflag("h", "help", "print this help menu"); let matches = match opts.parse(&args[1..]) { @@ -49,6 +53,30 @@ impl Config { PathBuf::from(".") }; + let stdout = if let Some(dir) = matches.opt_str("o") { + PathBuf::from(dir) + } else if let Some(mut dir) = config_dir() { + dir.push("sup"); + dir.push("stdout.log"); + dir + } else { + let mut p = PathBuf::from("."); + p.push("stdout.log"); + p + }; + + let stderr = if let Some(dir) = matches.opt_str("e") { + PathBuf::from(dir) + } else if let Some(mut dir) = config_dir() { + dir.push("sup"); + dir.push("stderr.log"); + dir + } else { + let mut p = PathBuf::from("."); + p.push("stderr.log"); + p + }; + let mut log_level: LevelFilter = LevelFilter::Info; if let Some(raw_level) = matches.opt_str("l") { @@ -69,6 +97,8 @@ impl Config { Config { config_directory, log_level, + stdout, + stderr, } } }