aboutsummaryrefslogtreecommitdiff
path: root/src/logging.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/logging.rs')
-rw-r--r--src/logging.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/logging.rs b/src/logging.rs
index bca8a7f0..66cd8ddd 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -22,7 +22,7 @@ use log::{self, Level};
use time;
use std::env;
-use std::fs::{File, OpenOptions};
+use std::fs::{self, File, OpenOptions};
use std::io::{self, LineWriter, Stdout, Write};
use std::path::PathBuf;
use std::process;
@@ -78,6 +78,10 @@ impl LoggerProxy {
self.errors.store(false, Ordering::Relaxed);
self.warnings.store(false, Ordering::Relaxed);
}
+
+ pub fn delete_log(&mut self) {
+ self.logfile_proxy.delete_log();
+ }
}
struct Logger {
@@ -154,6 +158,17 @@ struct OnDemandLogFileProxy {
path: String,
}
+impl OnDemandLogFileProxy {
+ fn delete_log(&mut self) {
+ if self.created.load(Ordering::Relaxed) {
+ if fs::remove_file(&self.path).is_ok() {
+ let _ = writeln!(io::stdout(), "Deleted log file at {:?}", self.path);
+ self.created.store(false, Ordering::Relaxed);
+ }
+ }
+ }
+}
+
struct OnDemandLogFile {
file: Option<LineWriter<File>>,
created: Arc<AtomicBool>,