Fix log files being opened as unicode files (#5545)

This commit is contained in:
Philipp Moritz
2019-08-27 12:47:00 -07:00
committed by Robert Nishihara
parent 52a6a1b9f7
commit ddfababb82
2 changed files with 32 additions and 1 deletions
+5 -1
View File
@@ -144,7 +144,7 @@ class LogMonitor(object):
# file.
if file_size > file_info.size_when_last_opened:
try:
f = open(file_info.filename, "r")
f = open(file_info.filename, "rb")
except (IOError, OSError) as e:
if e.errno == errno.ENOENT:
logger.warning("Warning: The file {} was not "
@@ -179,6 +179,10 @@ class LogMonitor(object):
for _ in range(max_num_lines_to_read):
try:
next_line = file_info.file_handle.readline()
# Replace any characters not in UTF-8 with
# a replacement character, see
# https://stackoverflow.com/a/38565489/10891801
next_line = next_line.decode("utf-8", "replace")
if next_line == "":
break
if next_line[-1] == "\n":