From 499989fb17ee29b0bea87bc0e7def317af842aa3 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 e99da773c..08780a2b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,9 +100,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(), @@ -111,9 +111,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(),