diff options
Diffstat (limited to 'crates/core/plugin_sm/src/log_file.rs')
-rw-r--r-- | crates/core/plugin_sm/src/log_file.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/core/plugin_sm/src/log_file.rs b/crates/core/plugin_sm/src/log_file.rs new file mode 100644 index 00000000..86d50a7c --- /dev/null +++ b/crates/core/plugin_sm/src/log_file.rs @@ -0,0 +1,25 @@ +use std::path::PathBuf; +use tokio::fs::File; +use tokio::io::BufWriter; + +pub struct LogFile { + path: PathBuf, + buffer: BufWriter<File>, +} + +impl LogFile { + pub async fn try_new(path: PathBuf) -> Result<LogFile, std::io::Error> { + let file = File::create(path.clone()).await?; + let buffer = BufWriter::new(file); + + Ok(LogFile { path, buffer }) + } + + pub fn path(&self) -> &str { + &self.path.to_str().unwrap_or("/var/log/tedge/agent") + } + + pub fn buffer(&mut self) -> &mut BufWriter<File> { + &mut self.buffer + } +} |