mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-25 08:47:18 +02:00
fix: Fix tests and better logging and history 🐛
This commit is contained in:
parent
b3683ae548
commit
08c30cf912
4 changed files with 137 additions and 64 deletions
26
src/main.rs
26
src/main.rs
|
@ -24,6 +24,7 @@ use std::env;
|
|||
use std::error::Error;
|
||||
use std::io::{self, Write};
|
||||
use std::panic;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
|
@ -62,19 +63,22 @@ pub fn destruct_terminal() {
|
|||
execute!(io::stdout(), cursor::Show).unwrap();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
better_panic::install();
|
||||
pub fn initialize_logging() {
|
||||
let data_local_dir = if let Ok(s) = std::env::var("TASKWARRIOR_TUI_DATA") {
|
||||
PathBuf::from(s)
|
||||
} else {
|
||||
dirs::data_local_dir()
|
||||
.expect("Unable to find data directory for taskwarrior-tui")
|
||||
.join("taskwarrior-tui")
|
||||
};
|
||||
|
||||
let data_local_dir = dirs::data_local_dir()
|
||||
.expect("Unable to open data local directory.")
|
||||
.join("taskwarrior-tui");
|
||||
std::fs::create_dir_all(&data_local_dir).unwrap_or_else(|_| panic!("Unable to create {:?}", data_local_dir));
|
||||
|
||||
let logfile = FileAppender::builder()
|
||||
.encoder(Box::new(PatternEncoder::new(LOG_PATTERN)))
|
||||
.append(false)
|
||||
.build(data_local_dir.join("taskwarrior-tui.log"))
|
||||
.unwrap();
|
||||
.expect("Failed to build log file appender.");
|
||||
|
||||
let levelfilter = match std::env::var("TASKWARRIOR_TUI_LOG_LEVEL")
|
||||
.unwrap_or_else(|_| "info".to_string())
|
||||
|
@ -91,9 +95,15 @@ fn main() {
|
|||
.appender(Appender::builder().build("logfile", Box::new(logfile)))
|
||||
.logger(Logger::builder().build("taskwarrior_tui", levelfilter))
|
||||
.build(Root::builder().appender("logfile").build(LevelFilter::Info))
|
||||
.unwrap();
|
||||
.expect("Failed to build logging config.");
|
||||
|
||||
log4rs::init_config(config).unwrap();
|
||||
log4rs::init_config(config).expect("Failed to initialize logging.");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
better_panic::install();
|
||||
|
||||
initialize_logging();
|
||||
|
||||
let matches = cli::generate_cli_app().get_matches();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue