From 80dfbd31793b28c540e2cdbb43333b9ef78ed9b7 Mon Sep 17 00:00:00 2001 From: jo Date: Mon, 31 Jan 2022 13:29:14 +0100 Subject: [PATCH] fix(shared): set logger encoding and dont assume encoding Older versions of python might have ascii as default, we should not assume that the default encoding always is "utf-8" when opening files. --- shared/libretime_shared/logging.py | 2 ++ shared/setup.py | 1 - shared/tests/logging_test.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shared/libretime_shared/logging.py b/shared/libretime_shared/logging.py index aa43a141d..50f77b5a5 100644 --- a/shared/libretime_shared/logging.py +++ b/shared/libretime_shared/logging.py @@ -75,6 +75,7 @@ def setup_logger( "serialize": serialize, "rotation": "12:00", "retention": "7 days", + "encoding": "utf-8", } ) @@ -108,6 +109,7 @@ def create_task_logger( "serialize": serialize, "rotation": "12:00", "retention": "7 days", + "encoding": "utf-8", } ], ) diff --git a/shared/setup.py b/shared/setup.py index 55af5d6f7..bfa60ca6d 100644 --- a/shared/setup.py +++ b/shared/setup.py @@ -18,7 +18,6 @@ setup( package_data={"": ["py.typed"]}, install_requires=[ "click>=8.0.3", - # Pinned until https://github.com/Delgan/loguru/issues/581 is fixed "loguru==0.6.0", "pydantic", "pyyaml", diff --git a/shared/tests/logging_test.py b/shared/tests/logging_test.py index a80512275..960babd39 100644 --- a/shared/tests/logging_test.py +++ b/shared/tests/logging_test.py @@ -48,5 +48,5 @@ def test_setup_logger(tmp_path: Path): extra_logger.complete() logger.complete() - assert len(log_filepath.read_text().splitlines()) == 1 - assert len(extra_log_filepath.read_text().splitlines()) == 1 + assert len(log_filepath.read_text(encoding="utf-8").splitlines()) == 1 + assert len(extra_log_filepath.read_text(encoding="utf-8").splitlines()) == 1