From a8009b100fc07f94556d91b9db3a9c7295d8e005 Mon Sep 17 00:00:00 2001 From: Johnny Miller Date: Sat, 4 Nov 2023 10:27:46 +0800 Subject: [PATCH] fix($log): retain log files by local date; override the default stderr (console) if console is available hotfix/7.2 [skip ci] --- .../configuration/loguru_configuration.py | 11 ++++++++--- setup.cfg | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/python_boilerplate/configuration/loguru_configuration.py b/python_boilerplate/configuration/loguru_configuration.py index 9699b8e..727a137 100644 --- a/python_boilerplate/configuration/loguru_configuration.py +++ b/python_boilerplate/configuration/loguru_configuration.py @@ -41,8 +41,13 @@ compression="gz", serialize=False, ) -# Override the default stderr (console) -logger.add(sys.stderr, level=log_level, format=_message_format) +stderr = sys.stderr +if stderr is None: + logger.warning("Detected no-console mode") +else: + # Override the default stderr (console) if console is available + logger.add(stderr, level=log_level, format=_message_format) + logger.warning("Detected console mode") class InterceptHandler(logging.Handler): @@ -82,7 +87,7 @@ def emit(self, record: LogRecord) -> None: def retain_log_files() -> None: - now = arrow.get() + now = arrow.now("local") dates = { date.format("YYYY-MM-DD") for date in Arrow.range("day", now.shift(days=-7), end=now) diff --git a/setup.cfg b/setup.cfg index e328807..6111900 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = python_boilerplate -version = 7.1 +version = 7.2 description = A boilerplate project for Python. long_description = file: README.md long_description_content_type = text/markdown