From 60a0e81e6f42438bc7de94d643f89650bc26cb31 Mon Sep 17 00:00:00 2001 From: Yihuang Yu Date: Fri, 5 Jan 2024 21:12:46 +0800 Subject: [PATCH] fix(utils_logfile.log_line): Open file with 'a' mode for safer writing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit utils_logfile.log_line currently uses 'w' mode to open log files, this causes some log contents missed when closing the log file. For example, when we close the log file, there are some contents in the cache and waiting for writing to the log, so need to reopen it, if use 'w' mode, old contents will be truncated. Suggested-by: Lukáš Doktor Signed-off-by: Yihuang Yu --- virttest/utils_logfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/virttest/utils_logfile.py b/virttest/utils_logfile.py index bb7ff7fe51..bbe3ba200e 100644 --- a/virttest/utils_logfile.py +++ b/virttest/utils_logfile.py @@ -76,7 +76,7 @@ def log_line(filename, line): os.makedirs(os.path.dirname(log_file)) except OSError: pass - _open_log_files[base_file] = open(log_file, "w") + _open_log_files[base_file] = open(log_file, "a") timestr = time.strftime("%Y-%m-%d %H:%M:%S") try: line = string_safe_encode(line)