Skip to content

Commit

Permalink
Add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
zkxs committed Jun 29, 2024
1 parent 72f67c2 commit 5fcf3c6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -68,7 +70,7 @@ fn get_log_dir() -> io::Result<PathBuf> {
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())
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
Expand All @@ -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)?;
}

Expand Down

0 comments on commit 5fcf3c6

Please sign in to comment.