From 97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 23:59:39 +0200 Subject: add logging --- src/main.rs | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index e67e535..1284e0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ use backup::Backup; use config::Config; use packages::{pacman::Pacman, PackageManager}; +use tracing::{debug, info, level_filters::LevelFilter}; +use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; mod backup; mod config; @@ -11,30 +13,39 @@ mod pathinfo; fn main() -> color_eyre::Result<()> { color_eyre::install()?; + let file_appender = tracing_appender::rolling::never("./", "arps.log"); + let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); + + tracing_subscriber::registry() + .with( + fmt::layer() + .with_writer(non_blocking) + .with_file(false) + .with_ansi(false) + .without_time(), + ) + .with(fmt::layer().with_file(false).without_time()) + .with( + EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(), + ) + .init(); + debug!("logging initialized"); + let mut cfg = Config::load()?; cfg.user.push("fx".to_string()); cfg.directories.push("~/.config/nvim".to_string()); - // cfg.directories.push("~/.config/hypr".to_string()); cfg.root = "./backup".to_string(); - // cfg.root = "./backup-test".to_string(); - // cfg.directories.push("u:/code/proj/fxbaup/backup-test-dir".to_string()); let pacman = Pacman; let pkgs = pacman.get_installed()?; - - let backup = Backup::create(&cfg, pkgs)?; - // println!("{backup:#?}"); - - backup.save(&cfg)?; - - // PathInfo::compare_to_last_modified(&cfg, &LocationRoot::User("fx".to_string()), "code/proj/fxbaub/backup-test-dir/size.txt")?; - // PathInfo::compare_to_last_modified(&cfg, &LocationRoot::User("fx".to_string()), "code/proj/fxbaub/backup-test-dir/content.txt")?; - - // let index = Backup::get_index(&cfg, None)?; - - // println!("{index:#?}"); - - // let fi = FileInfo::new("~/.config/nvim", &cfg)?; - // println!("{:?}", fi.get_absolute_path()); + let backup = Backup::create(&cfg, pkgs); + // info!(?backup); + // pacman.install(vec![Package { + // id: "lapce".to_string(), + // version: "0.4.2-1".to_string(), + // explicit: true, + // }])?; Ok(()) } -- cgit v1.2.3