Handle unicode errors in LogPrinter

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-25 15:39:23 -07:00 committed by Joffrey F
parent b28bcd613a
commit abdeed7bb6
1 changed files with 11 additions and 1 deletions

View File

@ -102,8 +102,18 @@ class LogPrinter(object):
# active containers to tail, so continue
continue
self.write(line)
def write(self, line):
try:
self.output.write(line)
self.output.flush()
except UnicodeEncodeError:
# This may happen if the user's locale settings don't support UTF-8
# and UTF-8 characters are present in the log line. The following
# will output a "degraded" log with unsupported characters
# replaced by `?`
self.output.write(line.encode('ascii', 'replace').decode())
self.output.flush()
def remove_stopped_threads(thread_map):