From 8fd9c0d72c3b1377c1793816b42bd39c1ce48bfd Mon Sep 17 00:00:00 2001 From: LKuemmel <76958050+LKuemmel@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:03:01 +0100 Subject: [PATCH] Persistent Logging for data migration (#1359) * log data migration to persistent log * fix --- packages/helpermodules/data_migration/data_migration.py | 2 +- packages/helpermodules/logger.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/helpermodules/data_migration/data_migration.py b/packages/helpermodules/data_migration/data_migration.py index 5d926de8eb..1c53929d9e 100644 --- a/packages/helpermodules/data_migration/data_migration.py +++ b/packages/helpermodules/data_migration/data_migration.py @@ -28,7 +28,7 @@ from helpermodules.utils import thread_handler from helpermodules.pub import Pub -log = logging.getLogger(__name__) +log = logging.getLogger("data_migration") def get_rounding_function_by_digits(digits: Union[int, None]) -> Callable: diff --git a/packages/helpermodules/logger.py b/packages/helpermodules/logger.py index 21874cdc61..5a5d33c4b0 100644 --- a/packages/helpermodules/logger.py +++ b/packages/helpermodules/logger.py @@ -7,6 +7,7 @@ FORMAT_STR_DETAILED = '%(asctime)s - {%(name)s:%(lineno)s} - {%(levelname)s:%(threadName)s} - %(message)s' FORMAT_STR_SHORT = '%(asctime)s - %(message)s' RAMDISK_PATH = str(Path(__file__).resolve().parents[2]) + '/ramdisk/' +PERSISTENT_LOG_PATH = str(Path(__file__).resolve().parents[2]) + '/data/log/' def filter_neg(name: str, record) -> bool: @@ -31,6 +32,13 @@ def mb_to_bytes(megabytes: int) -> int: logging.getLogger().handlers[0].addFilter(functools.partial(filter_neg, "Internal Chargepoint")) logging.getLogger().handlers[0].addFilter(functools.partial(filter_neg, "smarthome")) + data_migration_log = logging.getLogger("data_migration") + data_migration_log.propagate = False + data_migration_file_handler = RotatingFileHandler( + PERSISTENT_LOG_PATH + 'data_migration.log', maxBytes=mb_to_bytes(3), backupCount=1) + data_migration_file_handler.setFormatter(logging.Formatter(FORMAT_STR_SHORT)) + data_migration_log.addHandler(data_migration_file_handler) + mqtt_log = logging.getLogger("mqtt") mqtt_log.propagate = False mqtt_file_handler = RotatingFileHandler(RAMDISK_PATH + 'mqtt.log', maxBytes=mb_to_bytes(3), backupCount=1)