forked from akanyan/STARTLINER
feat: verbose toggle, info tab, many misc fixes
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use std::hash::{DefaultHasher, Hash, Hasher};
|
||||
use std::time::SystemTime;
|
||||
use crate::model::config::GlobalConfig;
|
||||
use crate::model::patch::PatchFileVec;
|
||||
use crate::pkg::{Feature, Status};
|
||||
@ -7,6 +8,7 @@ use crate::{model::misc::Game, pkg::PkgKey};
|
||||
use crate::pkg_store::PackageStore;
|
||||
use crate::util;
|
||||
use anyhow::{anyhow, Result};
|
||||
use fern::colors::{Color, ColoredLevelConfig};
|
||||
use tauri::AppHandle;
|
||||
|
||||
pub struct GlobalState {
|
||||
@ -34,6 +36,8 @@ impl AppData {
|
||||
.and_then(|s| Ok(serde_json::from_str::<GlobalConfig>(&s)?))
|
||||
.unwrap_or_default();
|
||||
|
||||
Self::init_logger(&cfg);
|
||||
|
||||
let profile = match cfg.recent_profile {
|
||||
Some((game, ref name)) => Profile::load(game, name.clone()).ok(),
|
||||
None => None
|
||||
@ -127,4 +131,36 @@ impl AppData {
|
||||
p.fix(&self.pkgs);
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logger(cfg: &GlobalConfig) {
|
||||
let mut fern_builder;
|
||||
let colors = ColoredLevelConfig::new()
|
||||
.debug(Color::Green)
|
||||
.info(Color::Blue)
|
||||
.warn(Color::Yellow)
|
||||
.error(Color::Red);
|
||||
|
||||
fern_builder = fern::Dispatch::new()
|
||||
.format(move |out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"[{} {} {}] {}",
|
||||
humantime::format_rfc3339_seconds(SystemTime::now()),
|
||||
colors.color(record.level()),
|
||||
record.target(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file(util::data_dir().join("log.txt")).expect("unable to initialize the logger"));
|
||||
|
||||
if cfg.verbose == true {
|
||||
fern_builder = fern_builder.level(log::LevelFilter::Debug);
|
||||
} else {
|
||||
fern_builder = fern_builder.level(log::LevelFilter::Info);
|
||||
}
|
||||
|
||||
if let Err(e) = fern_builder.apply() {
|
||||
panic!("unable to initialize the logger? {:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user