Skip to content

Commit 50282eb

Browse files
authored
feat: summary of failed files in verbose log and log file (#10)
1 parent e4fabef commit 50282eb

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/logger.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::fs::File;
44
use std::io::Write;
55
use std::path::{Display, PathBuf};
6-
use std::sync::{Arc, Mutex};
6+
use std::sync::{Arc, Mutex, MutexGuard};
77

88
pub(crate) struct Logger {
99
progress: Arc<Progress>,
@@ -45,6 +45,20 @@ impl Logger {
4545
}
4646
}
4747

48+
pub(crate) fn append_failed_paths_to_log(&self, paths: &MutexGuard<Vec<String>>) {
49+
if paths.len() == 0 {
50+
return;
51+
}
52+
53+
let static_line = "\nThe following files were not processed due to the errors above:";
54+
55+
let paths_lines = paths.join("\n");
56+
57+
let to_write = format!("{}\n{}", static_line, paths_lines);
58+
59+
self.write_to_log(&to_write);
60+
}
61+
4862
pub(crate) fn get_log_path(&self) -> Display {
4963
self.log_path.display()
5064
}

src/main.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ fn main() {
9696
}
9797

9898
let paths = Arc::new(Mutex::new(paths));
99+
let failed_paths: Arc<Mutex<Vec<String>>> = Arc::new(Mutex::new(vec![]));
99100
let progress = Arc::new(Progress::new(paths.lock().unwrap().len()));
100101
let logger = Arc::new(Logger::new(Arc::clone(&progress)));
101102
let mut thread_handles = vec![];
@@ -104,6 +105,7 @@ fn main() {
104105

105106
for thread in 0..cmd_args.thread_count {
106107
let paths = Arc::clone(&paths);
108+
let failed_paths = Arc::clone(&failed_paths);
107109
let progress = Arc::clone(&progress);
108110
let logger = Arc::clone(&logger);
109111
let verbose = cmd_args.verbose;
@@ -231,6 +233,8 @@ fn main() {
231233
thread,
232234
verbose,
233235
);
236+
237+
failed_paths.lock().unwrap().push(path.display().to_string());
234238
}
235239
} else {
236240
eprintln!("[THREAD {thread}] -- There was an error running ffmpeg. Please check if it's correctly installed and working as intended.");
@@ -258,4 +262,14 @@ fn main() {
258262
logger.get_log_path()
259263
);
260264
println!("{final_output}");
265+
266+
let failed_paths = failed_paths.lock().unwrap();
267+
268+
logger.append_failed_paths_to_log(&failed_paths);
269+
if cmd_args.verbose && failed_paths.len() > 0 {
270+
println!("\nThe following files were not processed due to the errors above:");
271+
for path in failed_paths.iter() {
272+
println!("{path}");
273+
}
274+
}
261275
}

0 commit comments

Comments
 (0)