Skip to content

Commit

Permalink
Fix UnicodeEncodeError. When no locale env has been explicitly set, t…
Browse files Browse the repository at this point in the history
…he default is ASCII (ANSI_X3.4-1968). Then the logger can raise an UnicodeEncodeError"
  • Loading branch information
loic-couderc committed Nov 13, 2017
1 parent 72de95d commit aebac2c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scripts/matam_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def update_logger_settings(logger_filepath, verbose, debug):
update logging level and logging format accordinlgy to verbose/debug flag.
add a file logger for root/runner logger.
"""
file_handler = logging.FileHandler(filename=logger_filepath)
file_handler = logging.FileHandler(filename=logger_filepath, encoding='utf8')
file_handler.formatter = logging.Formatter('%(levelname)s - %(message)s')
logger.addHandler(file_handler)
if debug:
Expand Down
4 changes: 3 additions & 1 deletion scripts/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def logged_call(command, verbose=False):
with subprocess.Popen(command, stdout=stdout, stderr=stderr, shell=True, bufsize=0) as process:
if verbose:
while process.poll() is None:
logger.info(os.read(process.stdout.fileno(), 1024).decode("utf-8", "ignore"))
message = os.read(process.stdout.fileno(), 1024).decode()
logger.info(message)


# rehabilitate previous handler
for handler in logger.handlers:
Expand Down

0 comments on commit aebac2c

Please sign in to comment.