Skip to content

Commit

Permalink
Persistent Logging for data migration (#1359)
Browse files Browse the repository at this point in the history
* log data migration to persistent log

* fix
  • Loading branch information
LKuemmel authored Jan 19, 2024
1 parent 1197264 commit 8fd9c0d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/helpermodules/data_migration/data_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions packages/helpermodules/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 8fd9c0d

Please sign in to comment.