feat(logging): add --log arg to enable logs
and/or to pass a custom log directory.
This commit is contained in:
30
src/main.rs
30
src/main.rs
@@ -3,7 +3,6 @@ mod common;
|
||||
mod config;
|
||||
mod constants;
|
||||
mod events;
|
||||
#[cfg(debug_assertions)]
|
||||
mod logging;
|
||||
|
||||
mod args;
|
||||
@@ -17,21 +16,44 @@ mod widgets;
|
||||
mod sound;
|
||||
|
||||
use app::{App, FromAppArgs};
|
||||
use args::Args;
|
||||
use args::{Args, LOG_DIRECTORY_DEFAULT_MISSING_VALUE};
|
||||
use clap::Parser;
|
||||
use color_eyre::Result;
|
||||
use config::Config;
|
||||
use std::path::PathBuf;
|
||||
use storage::{AppStorage, Storage};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// init `Config`
|
||||
let cfg = Config::init()?;
|
||||
#[cfg(debug_assertions)]
|
||||
logging::Logger::new(cfg.log_dir).init()?;
|
||||
|
||||
color_eyre::install()?;
|
||||
|
||||
// get args given by CLI
|
||||
let args = Args::parse();
|
||||
// Note:
|
||||
// `log` arg can have three different values:
|
||||
// (1) not set => None
|
||||
// (2) set with path => Some(Some(path))
|
||||
// (3) set without path => Some(None)
|
||||
let custom_log_dir: Option<Option<&PathBuf>> = if let Some(path) = &args.log {
|
||||
if path.ne(PathBuf::from(LOG_DIRECTORY_DEFAULT_MISSING_VALUE).as_os_str()) {
|
||||
// (2)
|
||||
Some(Some(path))
|
||||
} else {
|
||||
// (3)
|
||||
Some(None)
|
||||
}
|
||||
} else {
|
||||
// (1)
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(log_dir) = custom_log_dir {
|
||||
let dir: PathBuf = log_dir.unwrap_or(&cfg.log_dir).to_path_buf();
|
||||
logging::Logger::new(dir).init()?;
|
||||
}
|
||||
|
||||
let mut terminal = terminal::setup()?;
|
||||
let events = events::Events::new();
|
||||
|
||||
Reference in New Issue
Block a user