Skip to content

Commit 75a01f6

Browse files
committed
fix logging encoding on windows
1 parent 93cff19 commit 75a01f6

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

plain2code.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def setup_logging(
118118

119119
if log_to_file and log_file_path:
120120
try:
121-
file_handler = logging.FileHandler(log_file_path, mode="w")
121+
file_handler = logging.FileHandler(log_file_path, mode="w", encoding="utf-8")
122122
file_handler.setFormatter(formatter)
123123
file_handler.setLevel(configured_log_level)
124124
root_logger.addHandler(file_handler)
@@ -268,6 +268,10 @@ def run_render():
268268

269269

270270
def main(): # noqa: C901
271+
if sys.platform == "win32":
272+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
273+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
274+
271275
args = parse_arguments()
272276

273277
# Handle early-exit flags before heavy initialization

plain2code_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def dump_to_file(self, filepath, formatter=None):
6565
return False
6666

6767
try:
68-
with open(filepath, "w") as f:
68+
with open(filepath, "w", encoding="utf-8") as f:
6969
for record in self.records:
7070
if formatter:
7171
msg = formatter.format(record)

0 commit comments

Comments
 (0)