diff options
author | Joffrey F <joffrey@docker.com> | 2017-08-25 15:39:23 -0700 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2017-08-28 15:21:39 -0700 |
commit | abdeed7bb6ab4e384a9a93fa7020a5258c704ce6 (patch) | |
tree | f1ad2e04d4819ac1bf863c959785ed87217f8fc8 | |
parent | b28bcd613a02aae376a0f16e3d7a457a91347734 (diff) |
Handle unicode errors in LogPrinter
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | compose/cli/log_printer.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/compose/cli/log_printer.py b/compose/cli/log_printer.py index 043d3d06..60bba8da 100644 --- a/compose/cli/log_printer.py +++ b/compose/cli/log_printer.py @@ -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): |