From 541de8b7578c66ca0ff7283c21dd48ddcd5a6392 Mon Sep 17 00:00:00 2001 From: Yu Li Date: Wed, 31 May 2023 16:33:47 +0800 Subject: [PATCH] logger: use `write` with `\r\n` instead of `writeln` The device manager will set tty or pty to raw mode, all the `\n` will be LF without CR, which makes the output difficult to read. This commit solves it by using `write` with `\r\n` instead of `writeln`, which can print CR and LF explicitly. Signed-off-by: Yu Li --- src/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bcca2900f..272ef1c4c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,9 +92,9 @@ impl log::Log for Logger { let duration = now.duration_since(self.start); if record.file().is_some() && record.line().is_some() { - writeln!( + write!( *(*(self.output.lock().unwrap())), - "cloud-hypervisor: {:.6?}: <{}> {}:{}:{} -- {}", + "cloud-hypervisor: {:.6?}: <{}> {}:{}:{} -- {}\r\n", duration, std::thread::current().name().unwrap_or("anonymous"), record.level(), @@ -103,9 +103,9 @@ impl log::Log for Logger { record.args() ) } else { - writeln!( + write!( *(*(self.output.lock().unwrap())), - "cloud-hypervisor: {:.6?}: <{}> {}:{} -- {}", + "cloud-hypervisor: {:.6?}: <{}> {}:{} -- {}\r\n", duration, std::thread::current().name().unwrap_or("anonymous"), record.level(),