From 1135e0679ee82f076698c3bb7646ca0b796fbead Mon Sep 17 00:00:00 2001 From: TOUL Date: Thu, 29 Jun 2023 16:48:29 +0200 Subject: [PATCH] FIX logger mlflow --- source/api/logger.py | 8 ++++++++ source/api/main.py | 7 +------ source/infrastructure/file_system_model_handler.py | 5 +++-- 3 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 source/api/logger.py diff --git a/source/api/logger.py b/source/api/logger.py new file mode 100644 index 0000000..bb04209 --- /dev/null +++ b/source/api/logger.py @@ -0,0 +1,8 @@ +import logging + +from config.monitoring_config import API_LOGFILE_LOG + +logger = logging.getLogger("uvicorn") +logger.setLevel(logging.INFO) +handler = logging.FileHandler(API_LOGFILE_LOG) +logger.addHandler(handler) diff --git a/source/api/main.py b/source/api/main.py index 8c761eb..ef5f68b 100644 --- a/source/api/main.py +++ b/source/api/main.py @@ -4,7 +4,7 @@ from fastapi import FastAPI from config.api_server import SERVER_ADRESS -from config.monitoring_config import DB_CONNECTION_STRING, API_LOGFILE_LOG +from config.monitoring_config import DB_CONNECTION_STRING from source.domain.entities.customer_columns import DataSetColumns, Education from source.domain.entities.model_type import ModelType from source.domain.usecase.monitor import monitor @@ -13,11 +13,6 @@ from source.infrastructure.database_monitoring_handler import DataBaseMonitoringHandler from source.infrastructure.file_system_model_handler import FilSystemModelHandler -logger = logging.getLogger("uvicorn") -logger.setLevel(logging.INFO) -handler = logging.FileHandler(API_LOGFILE_LOG) -logger.addHandler(handler) - app = FastAPI(root_path=SERVER_ADRESS) model_handler = FilSystemModelHandler() monitoring_handler = DataBaseMonitoringHandler(connection_string=DB_CONNECTION_STRING) diff --git a/source/infrastructure/file_system_model_handler.py b/source/infrastructure/file_system_model_handler.py index fcc9a9e..7eaf0ff 100644 --- a/source/infrastructure/file_system_model_handler.py +++ b/source/infrastructure/file_system_model_handler.py @@ -6,6 +6,7 @@ from mlflow import MlflowException from models import MODEL_REGISTRY +from source.api.logger import logger from source.domain.entities.model_type import ModelType from source.domain.port.model_handler import ModelHandler @@ -19,8 +20,8 @@ def save_model(self, model) -> None: def load_model(self, model: ModelType): try: model = mlflow.pyfunc.load_model(model_uri=f"models:/customer/{model}") - logging.info('Successfully loaded model from MLflow') + logger.info('Successfully loaded model from MLflow') return model except MlflowException: - logging.info('Failed to load model from MLflow, loading default model') + logger.info('Failed to load model from MLflow, loading default model') return joblib.load(MODEL_PATH)