Log always to trace; may be disabled

This commit is contained in:
veeso 2021-05-16 15:12:01 +02:00
parent 7f9d92cbe9
commit faab67800f
2 changed files with 8 additions and 13 deletions

View file

@ -82,12 +82,11 @@ fn main() {
let mut remote_wrkdir: Option<PathBuf> = None;
let mut protocol: FileTransferProtocol = FileTransferProtocol::Sftp; // Default protocol
let mut ticks: Duration = Duration::from_millis(10);
let mut log_level: Option<logging::LevelFilter> = Some(logging::LevelFilter::Info);
let mut log_enabled: bool = true;
//Process options
let mut opts = Options::new();
opts.optopt("P", "password", "Provide password from CLI", "<password>");
opts.optopt("T", "ticks", "Set UI ticks; default 10ms", "<ms>");
opts.optflag("D", "debug", "Enable debug log level");
opts.optflag("q", "quiet", "Disable logging");
opts.optflag("v", "version", "");
opts.optflag("h", "help", "Print this menu");
@ -113,10 +112,7 @@ fn main() {
}
// Logging
if matches.opt_present("q") {
log_level = None;
}
if matches.opt_present("D") {
log_level = Some(logging::LevelFilter::Trace);
log_enabled = false;
}
// Match password
if let Some(passwd) = matches.opt_str("P") {
@ -169,8 +165,8 @@ fn main() {
Err(_) => PathBuf::from("/"),
};
// Setup logging
if let Some(log_level) = log_level {
if let Err(err) = logging::init(log_level) {
if log_enabled {
if let Err(err) = logging::init() {
eprintln!("Failed to initialize logging: {}", err);
}
}

View file

@ -29,15 +29,14 @@
use crate::system::environment::{get_log_paths, init_config_dir};
use crate::utils::file::open_file;
// ext
pub use simplelog::LevelFilter;
use simplelog::{ConfigBuilder, WriteLogger};
use simplelog::{ConfigBuilder, LevelFilter, WriteLogger};
use std::fs::File;
use std::path::PathBuf;
/// ### init
///
/// Initialize logger
pub fn init(log_level: LevelFilter) -> Result<(), String> {
pub fn init() -> Result<(), String> {
// Init config dir
let config_dir: PathBuf = match init_config_dir() {
Ok(Some(p)) => p,
@ -57,7 +56,7 @@ pub fn init(log_level: LevelFilter) -> Result<(), String> {
.set_time_format_str("%Y-%m-%dT%H:%M:%S%z")
.build();
// Make logger
WriteLogger::init(log_level, config, file)
WriteLogger::init(LevelFilter::Trace, config, file)
.map_err(|e| format!("Failed to initialize logger: {}", e))
}
@ -68,6 +67,6 @@ mod test {
#[test]
fn test_system_logging_setup() {
assert!(init(LevelFilter::Trace).is_ok());
assert!(init().is_ok());
}
}