From cc79b2f08a870f8d404eb3b6b36fb59a260713dc Mon Sep 17 00:00:00 2001 From: Gabriel Goller Date: Wed, 27 Nov 2024 12:46:50 +0100 Subject: [PATCH] log: ignore to_stdout parameter This parameter causes the FileLogger to duplicate the log output to stdout. This causes duplicate output on proxmox-backup-manager because this is now handled by tracing. This should be removed completely in the future. In the worst case this will only result in missing log lines on stdout (which is visible only on proxmox-backup-manager/client invocations anyway). Signed-off-by: Gabriel Goller [ TL: add doc-comment to struct, note why it can be removed ] Signed-off-by: Thomas Lamprecht --- proxmox-log/src/file_logger.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/proxmox-log/src/file_logger.rs b/proxmox-log/src/file_logger.rs index c3648976..1e67b450 100644 --- a/proxmox-log/src/file_logger.rs +++ b/proxmox-log/src/file_logger.rs @@ -17,7 +17,8 @@ pub struct FileLogOptions { pub read: bool, /// If set, ensure that the file is newly created or error out if already existing. pub exclusive: bool, - /// Duplicate logged messages to STDOUT, like tee + /// Duplicate logged messages to STDOUT, like tee. + /// NOTE: this is now handled by tracing, this option will be removed soon. pub to_stdout: bool, /// Prefix messages logged to the file with the current local time as RFC 3339 pub prefix_time: bool, @@ -103,11 +104,12 @@ impl FileLogger { pub fn log>(&mut self, msg: S) { let msg = msg.as_ref(); - if self.options.to_stdout { - let mut stdout = std::io::stdout(); - let _ = stdout.write_all(msg.as_bytes()); - let _ = stdout.write_all(b"\n"); - } + // TODO: remove whole to_stdout option, handled by tracing now + //if self.options.to_stdout { + // let mut stdout = std::io::stdout(); + // let _ = stdout.write_all(msg.as_bytes()); + // let _ = stdout.write_all(b"\n"); + //} let line = if self.options.prefix_time { let now = proxmox_time::epoch_i64(); @@ -128,16 +130,18 @@ impl FileLogger { impl std::io::Write for FileLogger { fn write(&mut self, buf: &[u8]) -> Result { - if self.options.to_stdout { - let _ = std::io::stdout().write(buf); - } + // TODO: remove whole to_stdout option, handled by tracing now + //if self.options.to_stdout { + // let _ = std::io::stdout().write(buf); + //} self.file.write(buf) } fn flush(&mut self) -> Result<(), std::io::Error> { - if self.options.to_stdout { - let _ = std::io::stdout().flush(); - } + // TODO: remove whole to_stdout option, handled by tracing now + //if self.options.to_stdout { + // let _ = std::io::stdout().flush(); + //} self.file.flush() } }