Commit 48637fbe5db86bce2eaa49c008446aef2abc6c7d
1 parent
5bf585f5
log_helper: ensure stdout handles unicode if logging there
This way, all modules that use the log_helper do not need to call ensure_stdout_handles_unicode (e.g. msodde, olevba)
Showing
1 changed file
with
4 additions
and
0 deletions
oletools/common/log_helper/log_helper.py
| ... | ... | @@ -44,6 +44,7 @@ General logging helpers |
| 44 | 44 | from ._json_formatter import JsonFormatter |
| 45 | 45 | from ._logger_adapter import OletoolsLoggerAdapter |
| 46 | 46 | from . import _root_logger_wrapper |
| 47 | +from ..io_encoding import ensure_stdout_handles_unicode | |
| 47 | 48 | import logging |
| 48 | 49 | import sys |
| 49 | 50 | |
| ... | ... | @@ -92,6 +93,9 @@ class LogHelper: |
| 92 | 93 | if self._is_enabled: |
| 93 | 94 | raise ValueError('re-enabling logging. Not sure whether that is ok...') |
| 94 | 95 | |
| 96 | + if stream in (None, sys.stdout): | |
| 97 | + ensure_stdout_handles_unicode() | |
| 98 | + | |
| 95 | 99 | log_level = LOG_LEVELS[level] |
| 96 | 100 | logging.basicConfig(level=log_level, format=log_format, stream=stream) |
| 97 | 101 | self._is_enabled = True | ... | ... |