diff --git a/gregory.example.toml b/gregory.example.toml index b6e76a7..86e58dc 100644 --- a/gregory.example.toml +++ b/gregory.example.toml @@ -27,15 +27,15 @@ max-threads = 10 [packages.some-librewolf-dependency] [packages.some-librewolf-dependency.compilation] - id = "1" - revision = "2" + id = "2" + revision = "4" threads = 2 image = "docker.io/library/debian" - commands = ["echo hi", "echo helloooooooooo"] + commands = ["echo hi", "echo helloooooooooo >&2"] volumes = ["other-workspace"] [packages.some-librewolf-dependency.packaging.fedora] - id = "1" + id = "3" revision = "2" threads = 2 image = "docker.io/library/fedora" diff --git a/src/logging.rs b/src/logging.rs new file mode 100644 index 0000000..6afe909 --- /dev/null +++ b/src/logging.rs @@ -0,0 +1,44 @@ +use crate::errors::Error; +use std::io::Write; +use std::{ + fs::{File, OpenOptions}, + os::unix::fs::FileExt, +}; + +/// The logger for gregory itself - NOT for jobs +pub(crate) struct Logger { + log_file: File, +} + +impl Logger { + pub(crate) fn new(path: String) -> Result<Logger, Error> { + match OpenOptions::new().append(true).open(path) { + Ok(f) => return Ok(Logger { log_file: f }), + Err(e) => { + return Err(Error::IOError(e)); + } + } + } + + /// Log a warning + /// + /// Fun gregory lore: I originally typo'd this as "Strign" and the linter didn't catch it for some reason + pub(crate) fn warning(&mut self, text: String) -> Result<(), Error> { + match writeln!(&mut self.log_file, "[WARNING] {}", text) { + Ok(_) => return Ok(()), + Err(e) => { + return Err(Error::IOError(e)); + } + } + } + + /// Log an error + pub(crate) fn error(&mut self, text: String) -> Result<(), Error> { + match writeln!(&mut self.log_file, "[ERROR] {}", text) { + Ok(_) => return Ok(()), + Err(e) => { + return Err(Error::IOError(e)); + } + } + } +} diff --git a/src/main.rs b/src/main.rs index 831b2ef..1e9b6f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ mod cli; mod data; mod errors; mod tests; +mod logging; fn main() { let cli = Cli::parse();