From e5b46df34997ea1d696ad58520a4a0cc4e6c4a53 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Sun, 9 Mar 2025 14:06:11 -0400 Subject: [PATCH 1/2] Allow saving the logs to a file again --- src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 309f2ea..2bd78eb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release use std::{ - fmt, fs, + fmt, + fs::{self, File}, + io::Write, path::PathBuf, sync::{ atomic::{AtomicU64, AtomicUsize}, @@ -502,6 +504,21 @@ impl egui_dock::TabViewer for TabViewer<'_> { if ui.button("Clear").clicked() { self.state.timer.0.write().unwrap().logs.clear(); } + if ui.button("Save").clicked() { + if let Err(e) = File::create("auto_splitter_logs.txt").and_then(|mut f| { + for LogMessage { message, .. } in + &self.state.timer.0.read().unwrap().logs + { + writeln!(f, "{message}")?; + } + Ok(()) + }) { + self.state.timer.0.write().unwrap().log( + format!("Failed to save log file: {}", e).into(), + LogType::Runtime(LogLevel::Error), + ); + } + } }); if scroll_to_end { ui.scroll_to_cursor(Some(Align::Max)); From f64cbfcb4fd9978c90750a7ba35d579a4d9227d6 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Sun, 9 Mar 2025 14:37:55 -0400 Subject: [PATCH 2/2] Save log timestamps and log types --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2bd78eb..18b339a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -506,10 +506,18 @@ impl egui_dock::TabViewer for TabViewer<'_> { } if ui.button("Save").clicked() { if let Err(e) = File::create("auto_splitter_logs.txt").and_then(|mut f| { - for LogMessage { message, .. } in + for LogMessage { time, message, ty } in &self.state.timer.0.read().unwrap().logs { - writeln!(f, "{message}")?; + let (target, level) = match ty { + LogType::AutoSplitterMessage => ("Auto Splitter", "INFO"), + LogType::Runtime(LogLevel::Trace) => ("Runtime", "TRACE"), + LogType::Runtime(LogLevel::Debug) => ("Runtime", "DEBUG"), + LogType::Runtime(LogLevel::Info) => ("Runtime", "INFO"), + LogType::Runtime(LogLevel::Warning) => ("Runtime", "WARN"), + LogType::Runtime(LogLevel::Error) => ("Runtime", "ERROR"), + }; + writeln!(f, "[{time}][{target}][{level}] {message}")?; } Ok(()) }) {