Skip to content

Commit

Permalink
Fix encoding issues - for py3
Browse files Browse the repository at this point in the history
  • Loading branch information
Shay Arbov committed Nov 28, 2017
1 parent 81de5c0 commit dd65409
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docker_test_tools/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def run_containers(self):
def start_log_collection(self):
"""Start a log collection process which writes docker-compose logs into a file."""
log.debug("Starting logs collection from environment containers")
self.logs_file = open(self.log_path, 'w')
self.logs_file = io.open(self.log_path, 'w', encoding=self.encoding)
self.logs_process = subprocess.Popen(
['docker-compose', '-f', self.compose_path, '-p', self.project_name, 'logs', '--no-color', '-f', '-t'],
stdout=self.logs_file, env=self.environment_variables
Expand Down Expand Up @@ -146,7 +146,7 @@ def split_logs(self):
# Write common log lines to all log files
if log_line.startswith(COMMON_LOG_PREFIX):
for services_log_file in services_log_files.values():
services_log_file.write("\n{log_line}\n".format(log_line=log_line))
services_log_file.write(u"\n{log_line}\n".format(log_line=log_line))

else:
# Write each log message to the appropriate log file (by prefix)
Expand All @@ -160,7 +160,7 @@ def split_logs(self):
# Create a log file if one doesn't exists
if service_name not in services_log_files:
services_log_files[service_name] = \
open(os.path.join(log_dir, service_name + '.log'), 'w')
io.open(os.path.join(log_dir, service_name + '.log'), 'w', encoding=self.encoding)

services_log_files[service_name].write(message)
finally:
Expand Down Expand Up @@ -449,7 +449,7 @@ def _get_environment_variables():
return env

def write_common_log_message(self, message):
self.logs_file.write('\n{prefix} {message}\n\n'.format(prefix=COMMON_LOG_PREFIX, message=message))
self.logs_file.write(u'\n{prefix} {message}\n\n'.format(prefix=COMMON_LOG_PREFIX, message=message))
self.logs_file.flush()

def _inspect(self, name, format='{{json}}'):
Expand Down

0 comments on commit dd65409

Please sign in to comment.