Skip to content

Commit ddc6acc

Browse files
authored
Merge pull request #24 from AlexKnauth/log-file
Allow saving the logs to a file again
1 parent 33a713c commit ddc6acc

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/main.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
22

33
use std::{
4-
fmt, fs,
4+
fmt,
5+
fs::{self, File},
6+
io::Write,
57
path::PathBuf,
68
sync::{
79
atomic::{AtomicU64, AtomicUsize},
@@ -502,6 +504,29 @@ impl egui_dock::TabViewer for TabViewer<'_> {
502504
if ui.button("Clear").clicked() {
503505
self.state.timer.0.write().unwrap().logs.clear();
504506
}
507+
if ui.button("Save").clicked() {
508+
if let Err(e) = File::create("auto_splitter_logs.txt").and_then(|mut f| {
509+
for LogMessage { time, message, ty } in
510+
&self.state.timer.0.read().unwrap().logs
511+
{
512+
let (target, level) = match ty {
513+
LogType::AutoSplitterMessage => ("Auto Splitter", "INFO"),
514+
LogType::Runtime(LogLevel::Trace) => ("Runtime", "TRACE"),
515+
LogType::Runtime(LogLevel::Debug) => ("Runtime", "DEBUG"),
516+
LogType::Runtime(LogLevel::Info) => ("Runtime", "INFO"),
517+
LogType::Runtime(LogLevel::Warning) => ("Runtime", "WARN"),
518+
LogType::Runtime(LogLevel::Error) => ("Runtime", "ERROR"),
519+
};
520+
writeln!(f, "[{time}][{target}][{level}] {message}")?;
521+
}
522+
Ok(())
523+
}) {
524+
self.state.timer.0.write().unwrap().log(
525+
format!("Failed to save log file: {}", e).into(),
526+
LogType::Runtime(LogLevel::Error),
527+
);
528+
}
529+
}
505530
});
506531
if scroll_to_end {
507532
ui.scroll_to_cursor(Some(Align::Max));

0 commit comments

Comments
 (0)