Logs
This commit is contained in:
parent
18f555e3e8
commit
cb3c12f708
|
|
@ -626,7 +626,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "post_maker"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"dirs",
|
||||
|
|
|
|||
|
|
@ -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 <https://piyushxcoder.in>"]
|
||||
|
|
|
|||
|
|
@ -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<String, ConfigFile>) {
|
|||
}
|
||||
|
||||
pub(crate) fn log_file() -> File {
|
||||
match File::open(&*LOG_FILE) {
|
||||
Ok(mut file) => {
|
||||
if is_file_30_days_old(&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) => 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);
|
||||
}
|
||||
},
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
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
|
||||
// }
|
||||
|
|
|
|||
10
src/main.rs
10
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(
|
||||
if let Err(e) = CombinedLogger::init(vec![
|
||||
WriteLogger::new(LevelFilter::Warn, Config::default(), config::log_file()),
|
||||
TermLogger::new(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
config::log_file(),
|
||||
)]) {
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
),
|
||||
]) {
|
||||
dialog::alert_default("Failed to start logger");
|
||||
panic!("Failed to start logger\n{:?}", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue