generated from dopt-python/py311
implemented logging including development state differentiation
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
import dotenv
|
||||
|
||||
if sys.stdout is None or sys.stderr is None:
|
||||
sys.stdout = open(os.devnull, "w")
|
||||
sys.stderr = open(os.devnull, "w")
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
@@ -4,19 +4,11 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
import dotenv
|
||||
from dopt_basics import io as io_
|
||||
|
||||
dotenv.load_dotenv()
|
||||
|
||||
# PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
LIB_PATH: Final[Path] = Path(__file__).resolve().parent
|
||||
|
||||
# DEV_DB_PATH = PROJECT_ROOT / "data/db"
|
||||
# DEV_DB_KONTAKTLISTE = DEV_DB_PATH / "wce_kontaktliste.db"
|
||||
# assert DEV_DB_KONTAKTLISTE.exists()
|
||||
# DEV_DB_CRM = DEV_DB_PATH / "wce_crm.db"
|
||||
# assert DEV_DB_CRM.exists()
|
||||
|
||||
BASE_PATH = io_.search_folder_path(
|
||||
LIB_PATH, stop_folder_name=os.getenv("DOPT_STOP_FOLDER_NAME", "python")
|
||||
@@ -25,10 +17,10 @@ assert BASE_PATH
|
||||
|
||||
|
||||
class Config:
|
||||
DB_PATH_CRM = BASE_PATH / os.getenv("DOPT_DB_CRM", "data/db/wce_crm.db")
|
||||
DB_PATH_MAIN = BASE_PATH / os.getenv("DOPT_DB_MAIN", "data/db/wce_grunderfassung.db")
|
||||
|
||||
|
||||
# def setup():
|
||||
# os.environ["DOPT_DB_KONTAKTLISTE"] = str(DEV_DB_KONTAKTLISTE)
|
||||
# os.environ["DOPT_DB_CRM"] = str(DEV_DB_CRM)
|
||||
DEVELOPMENT_STATE: bool = bool(os.getenv("DOPT_DEVELOPMENT", "0"))
|
||||
DB_PATH_CRM: Path = BASE_PATH / os.getenv("DOPT_DB_CRM", "data/db/wce_crm.db")
|
||||
DB_PATH_MAIN: Path = BASE_PATH / os.getenv(
|
||||
"DOPT_DB_MAIN", "data/db/wce_grunderfassung.db"
|
||||
)
|
||||
PATH_LOGGING: Path = BASE_PATH / os.getenv("DOPT_PATH_LOGGING", "data/d-opt.log")
|
||||
LOG_FILENAME: str = "dopt.log"
|
||||
|
||||
33
src/wce_crm/logging.py
Normal file
33
src/wce_crm/logging.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import logging
|
||||
|
||||
from dopt_basics.logging import BASE_LOGGER, setup_logging
|
||||
|
||||
from wce_crm.constants import Config
|
||||
|
||||
enable_stderr: bool = False
|
||||
enable_file: bool = True
|
||||
|
||||
if Config.DEVELOPMENT_STATE:
|
||||
enable_stderr = True
|
||||
enable_file = False
|
||||
|
||||
if not Config.PATH_LOGGING.exists():
|
||||
Config.PATH_LOGGING.mkdir()
|
||||
|
||||
setup_logging(
|
||||
enable_stderr=enable_stderr,
|
||||
enable_file=enable_file,
|
||||
logging_dir=Config.PATH_LOGGING,
|
||||
log_filename=Config.LOG_FILENAME,
|
||||
)
|
||||
logger_base = BASE_LOGGER.getChild("wce_crm")
|
||||
|
||||
# ** GUI
|
||||
logger_gui = logger_base.getChild("gui")
|
||||
logger_gui.setLevel(logging.DEBUG)
|
||||
logger_search_widget = logger_gui.getChild("search_widget")
|
||||
logger_search_widget.setLevel(logging.DEBUG)
|
||||
logger_get_data = logger_gui.getChild("get_data")
|
||||
logger_get_data.setLevel(logging.DEBUG)
|
||||
logger_auto_form = logger_gui.getChild("get_data_auto_form")
|
||||
logger_auto_form.setLevel(logging.DEBUG)
|
||||
Reference in New Issue
Block a user