Logs
This commit is contained in:
parent
18f555e3e8
commit
cb3c12f708
|
|
@ -626,7 +626,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "post_maker"
|
name = "post_maker"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "post_maker"
|
name = "post_maker"
|
||||||
version = "0.2.2"
|
version = "0.2.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Post Maker helps you to make post for Instagram and other Social Media apps easily."
|
description = "Post Maker helps you to make post for Instagram and other Social Media apps easily."
|
||||||
authors = ["PiyushXCoder <https://piyushxcoder.in>"]
|
authors = ["PiyushXCoder <https://piyushxcoder.in>"]
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,7 @@ use fltk::dialog;
|
||||||
use fltk_theme::ThemeType;
|
use fltk_theme::ThemeType;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{collections::HashMap, fs::File, path::PathBuf};
|
||||||
collections::HashMap,
|
|
||||||
fs::File,
|
|
||||||
path::PathBuf,
|
|
||||||
time::{Duration, SystemTime},
|
|
||||||
};
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
/// Directory where all Configurations are present
|
/// 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 {
|
pub(crate) fn log_file() -> File {
|
||||||
match File::open(&*LOG_FILE) {
|
// match File::open(&*LOG_FILE) {
|
||||||
Ok(mut file) => {
|
// Ok(mut file) => {
|
||||||
if is_file_30_days_old(&file) {
|
// if is_file_30_days_old(&file) {
|
||||||
match File::create(&*LOG_FILE) {
|
// match File::create(&*LOG_FILE) {
|
||||||
Ok(f) => file = f,
|
// Ok(f) => file = f,
|
||||||
Err(e) => {
|
// Err(e) => {
|
||||||
dialog::alert_default("Can't open log file!");
|
// dialog::alert_default("Can't open log file!");
|
||||||
panic!("{:?}", e);
|
// panic!("{:?}", e);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
file
|
// 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 {
|
// pub(crate) fn is_file_30_days_old(file: &File) -> bool {
|
||||||
if let Ok(meta) = file.metadata() {
|
// if let Ok(meta) = file.metadata() {
|
||||||
if let Ok(time) = meta.created() {
|
// if let Ok(time) = meta.created() {
|
||||||
if let Ok(dur) = SystemTime::now().duration_since(time) {
|
// if let Ok(dur) = SystemTime::now().duration_since(time) {
|
||||||
if dur > Duration::from_secs(60 * 60 * 24 * 30) {
|
// if dur > Duration::from_secs(60 * 60 * 24 * 30) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
false
|
// false
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
14
src/main.rs
14
src/main.rs
|
|
@ -47,11 +47,15 @@ fn main() {
|
||||||
let app = App::default();
|
let app = App::default();
|
||||||
WidgetTheme::new(globals::THEME.clone().into()).apply();
|
WidgetTheme::new(globals::THEME.clone().into()).apply();
|
||||||
|
|
||||||
if let Err(e) = CombinedLogger::init(vec![WriteLogger::new(
|
if let Err(e) = CombinedLogger::init(vec![
|
||||||
LevelFilter::Info,
|
WriteLogger::new(LevelFilter::Warn, Config::default(), config::log_file()),
|
||||||
Config::default(),
|
TermLogger::new(
|
||||||
config::log_file(),
|
LevelFilter::Info,
|
||||||
)]) {
|
Config::default(),
|
||||||
|
TerminalMode::Mixed,
|
||||||
|
ColorChoice::Auto,
|
||||||
|
),
|
||||||
|
]) {
|
||||||
dialog::alert_default("Failed to start logger");
|
dialog::alert_default("Failed to start logger");
|
||||||
panic!("Failed to start logger\n{:?}", e);
|
panic!("Failed to start logger\n{:?}", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue