From 5fd5b1f3f3d81f9dc46eb55d5448fb5c75f140e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Miller=20=28=E9=94=BA=E4=BF=8A=29?= Date: Mon, 8 Nov 2021 00:17:33 +0800 Subject: [PATCH] perf($db): refine ORM log when initializing db --- home_guardian/__init__.py | 3 ++- home_guardian/repository/model/base/model.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/home_guardian/__init__.py b/home_guardian/__init__.py index f0432ac..3bc0585 100644 --- a/home_guardian/__init__.py +++ b/home_guardian/__init__.py @@ -4,5 +4,6 @@ # Set up logging logging_conf_path = f"{get_root_path()}/logging.conf" -print(f"logging_conf_path = {logging_conf_path}, __file__ = {__file__}") +print(f"Start loading logging configuration. logging_conf_path = {logging_conf_path}, __file__ = {__file__}") logging.config.fileConfig(logging_conf_path) +print(f"Done loading logging configuration.") diff --git a/home_guardian/repository/model/base/model.py b/home_guardian/repository/model/base/model.py index aafdadd..9548aaa 100644 --- a/home_guardian/repository/model/base/model.py +++ b/home_guardian/repository/model/base/model.py @@ -1,11 +1,14 @@ -from peewee import Model, SqliteDatabase +import logging +from peewee import Model, SqliteDatabase from home_guardian.function_collection import get_root_path -base_dir = get_root_path() -print(f"base_dir: {base_dir}") -db = SqliteDatabase(f"{base_dir}/home_guardian.db") -print(f"Initialized db file: {db}") +log = logging.getLogger("rotatingFileLogger") + +db_path = f"{get_root_path()}/home_guardian.db" +log.info(f"SQLite database path: {db_path}") +db = SqliteDatabase(db_path) +log.info(f"Initialized db file: {db}") class BaseModel(Model):