]> git.proxmox.com Git - pve-installer.git/commitdiff
auto installer: log: print to stderr and include level
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 19 Apr 2024 10:07:00 +0000 (12:07 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 22 Apr 2024 12:31:37 +0000 (14:31 +0200)
and use the write! macro to write to the log file to avoid an
intermediate buffer.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
proxmox-auto-installer/src/log.rs

index d52912a7daac00380899df71b07ccf4f1719914e..50635ae8864877a15b4d59a8524e11224313303d 100644 (file)
@@ -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");
         }
     }