From 5fcf3c605f579992d2dcc9fb53f2dd1f51a1a96a Mon Sep 17 00:00:00 2001 From: Michael Ripley Date: Sat, 29 Jun 2024 17:44:40 -0500 Subject: [PATCH] Add more logging --- src/logging.rs | 4 +++- src/main.rs | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/logging.rs b/src/logging.rs index 04f9ed6..4cb6862 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -9,6 +9,7 @@ use std::fmt::{Display, Formatter}; use std::io::{BufWriter, Write}; use std::path::PathBuf; use std::time::SystemTime; + use directories::ProjectDirs; use file_rotate::{ContentLimit, FileRotate}; use file_rotate::suffix::AppendCount; @@ -24,6 +25,7 @@ impl LogFile { Self { write } } + /// evil hack to write timestamps in logs pub fn write_fmt(&mut self, args: fmt::Arguments<'_>) { write!(self.write, "{}: ", CurrentTime).expect("failed to write log timestamp"); self.write.write_fmt(args).expect("failed to write log arguments"); @@ -68,7 +70,7 @@ fn get_log_dir() -> io::Result { struct CurrentTime; impl Display for CurrentTime { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match SystemTime::UNIX_EPOCH.elapsed() { Ok(current_time) => write!(f, "{}", current_time.as_secs()), Err(e) => write!(f, "-{}", e.duration().as_secs()) diff --git a/src/main.rs b/src/main.rs index 4f3b2a4..5755e2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use std::fs::{self, File, OpenOptions}; use std::io::{BufRead, BufReader, BufWriter, Write}; use std::path::{Path, PathBuf}; use std::process::Command; + use crate::local_player_moderations as lpmod; mod local_player_moderations; @@ -63,8 +64,8 @@ impl Hooligan { } !remove }); - write_lines(path, lines)?; - writeln!(self.log, "removed {} shown avatar entries", removed); + write_lines(path.as_path(), lines)?; + writeln!(self.log, "removed {} shown avatar entries from {}", removed, path.file_name().unwrap().to_string_lossy()); } } } @@ -75,6 +76,7 @@ impl Hooligan { // we got args, blindly run them as a command let mut command = Command::new(command); command.args(args); + writeln!(self.log, "spawning {command:?}"); let _ = command.spawn().map_err(Error::Io)?; }