diff --git a/src/tools/file_logger.rs b/src/tools/file_logger.rs index cfd43401..ac6c83a6 100644 --- a/src/tools/file_logger.rs +++ b/src/tools/file_logger.rs @@ -47,6 +47,7 @@ pub struct FileLogOptions { #[derive(Debug)] pub struct FileLogger { file: std::fs::File, + file_name: std::path::PathBuf, options: FileLogOptions, } @@ -63,6 +64,23 @@ impl FileLogger { file_name: P, options: FileLogOptions, ) -> Result { + let file = Self::open(&file_name, &options)?; + + let file_name: std::path::PathBuf = file_name.as_ref().to_path_buf(); + + Ok(Self { file, file_name, options }) + } + + pub fn reopen(&mut self) -> Result<&Self, Error> { + let file = Self::open(&self.file_name, &self.options)?; + self.file = file; + Ok(self) + } + + fn open>( + file_name: P, + options: &FileLogOptions, + ) -> Result { let file = std::fs::OpenOptions::new() .read(options.read) .write(true) @@ -76,7 +94,7 @@ impl FileLogger { nix::unistd::chown(file_name.as_ref(), Some(backup_user.uid), Some(backup_user.gid))?; } - Ok(Self { file, options }) + Ok(file) } pub fn log>(&mut self, msg: S) {