Skip to content

Commit

Permalink
Set default stream encoding to utf-8 to logging handlers (#685)
Browse files Browse the repository at this point in the history
With the addition of characters that require unicode support to source files, it is necessary to a default encoding of `utf-8` to prevent errors such as `UnicodeEncodeError: 'charmap' codec can't encode character '\u017f' when parsing file names.`
  • Loading branch information
apop5 authored Jan 6, 2025
1 parent c4a8dd5 commit 6b53631
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions edk2toollib/log/file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class FileHandler(logging.FileHandler):
"""Object for handling basic logging output to files."""

def __init__(self, filename: str, mode: str = "w+") -> "FileHandler":
def __init__(self, filename: str, mode: str = "w+", encoding="utf-8") -> "FileHandler":
"""Init a file handler for the specified file."""
logging.FileHandler.__init__(self, filename, mode=mode)
logging.FileHandler.__init__(self, filename, mode=mode, encoding=encoding)

def handle(self, record: logging.LogRecord) -> bool:
"""Conditionally emit the specified logging record.
Expand Down
2 changes: 1 addition & 1 deletion edk2toollib/log/junit_report_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def create_new_testsuite(self, name: str, package: str) -> JunitReportTestSuite:

def Output(self, filepath: str) -> None:
"""Write report to file."""
f = open(filepath, "w")
f = open(filepath, "w", encoding="utf-8")
f.write("")
f.write('<?xml version="1.0" encoding="UTF-8"?>')
f.write("<testsuites>")
Expand Down

0 comments on commit 6b53631

Please sign in to comment.