From: Thomas Lamprecht Date: Fri, 19 Apr 2024 10:07:00 +0000 (+0200) Subject: auto installer: log: print to stderr and include level X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=34a1258355d78f684242d1ce6f51583ba8d08c26;p=pve-installer.git auto installer: log: print to stderr and include level and use the write! macro to write to the log file to avoid an intermediate buffer. Signed-off-by: Thomas Lamprecht --- diff --git a/proxmox-auto-installer/src/log.rs b/proxmox-auto-installer/src/log.rs index d52912a..50635ae 100644 --- a/proxmox-auto-installer/src/log.rs +++ b/proxmox-auto-installer/src/log.rs @@ -20,16 +20,16 @@ impl log::Log for AutoInstLogger { metadata.level() <= Level::Info } - /// Logs to stdout without log level and into log file including log level + /// Logs to both, stderr and into a log file fn log(&self, record: &Record) { if self.enabled(record.metadata()) { - println!("{}", record.args()); + eprintln!("{}: {}", record.level(), record.args()); let mut file = LOGFILE .get() .expect("could not get LOGFILE") .lock() .expect("could not get mutex for LOGFILE"); - file.write_all(format!("{} - {}\n", record.level(), record.args()).as_bytes()) + write!(file, "{}: {}\n", record.level(), record.args()) .expect("could not write to LOGFILE"); } }