From cb3c12f7081995146da29243d74d27912f8a7cd9 Mon Sep 17 00:00:00 2001 From: Piyush Mishra Date: Sat, 29 Jan 2022 23:47:42 +0530 Subject: [PATCH] Logs --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/config.rs | 70 ++++++++++++++++++++++++--------------------------- src/main.rs | 14 +++++++---- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26e79a8..db9143d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -626,7 +626,7 @@ dependencies = [ [[package]] name = "post_maker" -version = "0.2.2" +version = "0.2.3" dependencies = [ "clap", "dirs", diff --git a/Cargo.toml b/Cargo.toml index 3426a21..4ee62eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "post_maker" -version = "0.2.2" +version = "0.2.3" edition = "2021" description = "Post Maker helps you to make post for Instagram and other Social Media apps easily." authors = ["PiyushXCoder "] diff --git a/src/config.rs b/src/config.rs index 0c1f83e..84c4369 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,12 +19,7 @@ use fltk::dialog; use fltk_theme::ThemeType; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; -use std::{ - collections::HashMap, - fs::File, - path::PathBuf, - time::{Duration, SystemTime}, -}; +use std::{collections::HashMap, fs::File, path::PathBuf}; lazy_static! { /// Directory where all Configurations are present @@ -218,38 +213,39 @@ pub(crate) fn save_configs(configs: HashMap) { } pub(crate) fn log_file() -> File { - match File::open(&*LOG_FILE) { - Ok(mut file) => { - if is_file_30_days_old(&file) { - match File::create(&*LOG_FILE) { - Ok(f) => file = f, - Err(e) => { - dialog::alert_default("Can't open log file!"); - panic!("{:?}", e); - } - } - } - file + // match File::open(&*LOG_FILE) { + // Ok(mut file) => { + // if is_file_30_days_old(&file) { + // match File::create(&*LOG_FILE) { + // Ok(f) => file = f, + // Err(e) => { + // dialog::alert_default("Can't open log file!"); + // panic!("{:?}", e); + // } + // } + // } + // file + // } + // Err(_) => + match File::create(&*LOG_FILE) { + Ok(f) => f, + Err(e) => { + dialog::alert_default("Can't open log file!"); + panic!("{:?}", e); } - Err(_) => match File::create(&*LOG_FILE) { - Ok(f) => f, - Err(e) => { - dialog::alert_default("Can't open log file!"); - panic!("{:?}", e); - } - }, } + // } } -pub(crate) fn is_file_30_days_old(file: &File) -> bool { - if let Ok(meta) = file.metadata() { - if let Ok(time) = meta.created() { - if let Ok(dur) = SystemTime::now().duration_since(time) { - if dur > Duration::from_secs(60 * 60 * 24 * 30) { - return true; - } - } - } - } - false -} +// pub(crate) fn is_file_30_days_old(file: &File) -> bool { +// if let Ok(meta) = file.metadata() { +// if let Ok(time) = meta.created() { +// if let Ok(dur) = SystemTime::now().duration_since(time) { +// if dur > Duration::from_secs(60 * 60 * 24 * 30) { +// return true; +// } +// } +// } +// } +// false +// } diff --git a/src/main.rs b/src/main.rs index 498cc35..afb98c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,11 +47,15 @@ fn main() { let app = App::default(); WidgetTheme::new(globals::THEME.clone().into()).apply(); - if let Err(e) = CombinedLogger::init(vec![WriteLogger::new( - LevelFilter::Info, - Config::default(), - config::log_file(), - )]) { + if let Err(e) = CombinedLogger::init(vec![ + WriteLogger::new(LevelFilter::Warn, Config::default(), config::log_file()), + TermLogger::new( + LevelFilter::Info, + Config::default(), + TerminalMode::Mixed, + ColorChoice::Auto, + ), + ]) { dialog::alert_default("Failed to start logger"); panic!("Failed to start logger\n{:?}", e); }