Skip to content

Commit

Permalink
fix(utils_logfile.log_line): Open file with 'a' mode for safer writing
Browse files Browse the repository at this point in the history
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 <ldoktor@redhat.com>
Signed-off-by: Yihuang Yu <yihyu@redhat.com>
  • Loading branch information
PaulYuuu committed Jan 5, 2024
1 parent 26cc872 commit 60a0e81
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion virttest/utils_logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 60a0e81

Please sign in to comment.