diff --git a/virttest/utils_misc.py b/virttest/utils_misc.py index eb62273c1c..81f3761737 100644 --- a/virttest/utils_misc.py +++ b/virttest/utils_misc.py @@ -477,10 +477,9 @@ def log_line(filename, line): pass _open_log_files[base_file] = open(log_file, "w") timestr = time.strftime("%Y-%m-%d %H:%M:%S") - _open_log_files[base_file].write("%s: %s\n" - % (timestr, - line.encode(ENCODING, - 'ignore'))) + line = unicode("%s: %s" % (timestr, line), errors="ignore") + line = line.encode(ENCODING, errors='ignore') + _open_log_files[base_file].write("%s\n" % line) _open_log_files[base_file].flush() finally: _log_lock.release()