From 87b2e3b00cc3321ce20a3156f7cee6d3529dddb7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 6 Nov 2023 21:59:55 +0800 Subject: [PATCH] add use stderr option for stdio output stream --- lib_not_dr/logger/outstream.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib_not_dr/logger/outstream.py b/lib_not_dr/logger/outstream.py index 731c2ef..df33209 100644 --- a/lib_not_dr/logger/outstream.py +++ b/lib_not_dr/logger/outstream.py @@ -52,6 +52,7 @@ class StdioOutputStream(BaseOutputStream): level: int = LogLevel.info formatter: BaseFormatter = StdFormatter() + use_stderr: bool = True def write_stdout(self, message: LogMessage) -> None: if not self.enable: @@ -66,7 +67,10 @@ class StdioOutputStream(BaseOutputStream): return None if message.level < self.level: return None - print(self.formatter.format_message(message), end='', flush=message.flush, file=sys.stderr) + if self.use_stderr: + print(self.formatter.format_message(message), end='', flush=message.flush, file=sys.stderr) + else: + print(self.formatter.format_message(message), end='', flush=message.flush) return None def flush(self) -> None: