From b3907455e12d698ad0a5cf88456e7d1ba198cee6 Mon Sep 17 00:00:00 2001 From: akhdanre Date: Thu, 20 Mar 2025 13:11:44 +0700 Subject: [PATCH] fix: logger --- app/controllers/auth_controller.py | 8 ++++++-- app/database/db.py | 8 +++----- app/main.py | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/auth_controller.py b/app/controllers/auth_controller.py index f467814..ac6e6cd 100644 --- a/app/controllers/auth_controller.py +++ b/app/controllers/auth_controller.py @@ -18,7 +18,11 @@ class AuthController: dataSchema = LoginSchema(**data) response = self.auth_service.login(dataSchema) return ( - jsonify(ResponseSchema(message="Register success", data=response)), + jsonify( + ResponseSchema( + message="Register success", data=response + ).model_dump() + ), 200, ) except ValidationError as e: @@ -30,7 +34,7 @@ class AuthController: current_app.logger.error( f"Error during Google login: {str(e)}", exc_info=True ) - response = ResponseSchema( + response = ResponseSchema( message="Internal server error", data=None, meta=None ) return jsonify(response.model_dump()), 500 diff --git a/app/database/db.py b/app/database/db.py index 90f04e0..fe50adb 100644 --- a/app/database/db.py +++ b/app/database/db.py @@ -1,6 +1,5 @@ from flask_pymongo import PyMongo -from flask import Flask -from configs import Config +from flask import Flask, current_app def init_db(app: Flask) -> PyMongo: @@ -8,10 +7,9 @@ def init_db(app: Flask) -> PyMongo: mongo = PyMongo(app) mongo.cx.server_info() - print("✅ MongoDB connection successful!") - + app.logger.info("MongoDB connection established") return mongo except Exception as e: - print(f"❌ MongoDB connection failed: {e}") + app.logger.error(f"MongoDB connection failed: {e}") return None # Handle failure gracefully diff --git a/app/main.py b/app/main.py index 095c0b9..01a6d56 100644 --- a/app/main.py +++ b/app/main.py @@ -9,6 +9,7 @@ from database import init_db def createApp() -> Flask: app = Flask(__name__) app.config.from_object(Config) + LoggerConfig.init_logger(app) container = Container() @@ -27,7 +28,6 @@ def createApp() -> Flask: app.register_blueprint(user_blueprint, url_prefix="/api") # Initialize Logging - LoggerConfig.init_logger(app) return app