Skip to content

Commit

Permalink
FIX logger mlflow
Browse files Browse the repository at this point in the history
  • Loading branch information
TOUL committed Jun 29, 2023
1 parent d559860 commit 1135e06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 8 additions & 0 deletions source/api/logger.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 1 addition & 6 deletions source/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions source/infrastructure/file_system_model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

0 comments on commit 1135e06

Please sign in to comment.