add logger

This commit is contained in:
Dohyun Lim committed 2026-01-14 17:46:45 +09:00
1 parent 1acd8846ab
commit bf7b53c8e8
41 files changed
+1832 -694

No files matched your search

+10 -23
View File
@@ -1,4 +1,3 @@
import logging
import traceback
from functools import wraps
from typing import Any, Callable, TypeVar
@@ -7,8 +6,10 @@ from fastapi import FastAPI, HTTPException, Request, Response, status
from fastapi.responses import JSONResponse
from sqlalchemy.exc import SQLAlchemyError
from app.utils.logger import get_logger
# 로거 설정
logger = logging.getLogger(__name__)
logger = get_logger("core")
T = TypeVar("T")
@@ -159,16 +160,14 @@ def handle_db_exceptions(
raise
except SQLAlchemyError as e:
logger.error(f"[DB Error] {func.__name__}: {e}")
logger.error(traceback.format_exc())
print(f"[DB Error] {func.__name__}: {e}")
logger.debug(traceback.format_exc())
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail=error_message,
)
except Exception as e:
logger.error(f"[Unexpected Error] {func.__name__}: {e}")
logger.error(traceback.format_exc())
print(f"[Unexpected Error] {func.__name__}: {e}")
logger.debug(traceback.format_exc())
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="서비스 처리 중 예기치 않은 오류가 발생했습니다.",
@@ -205,8 +204,7 @@ def handle_external_service_exceptions(
except Exception as e:
msg = error_message or f"{service_name} 서비스 호출 중 오류가 발생했습니다."
logger.error(f"[{service_name} Error] {func.__name__}: {e}")
logger.error(traceback.format_exc())
print(f"[{service_name} Error] {func.__name__}: {e}")
logger.debug(traceback.format_exc())
raise HTTPException(
status_code=status.HTTP_502_BAD_GATEWAY,
detail=msg,
@@ -240,16 +238,14 @@ def handle_api_exceptions(
raise
except SQLAlchemyError as e:
logger.error(f"[API DB Error] {func.__name__}: {e}")
logger.error(traceback.format_exc())
print(f"[API DB Error] {func.__name__}: {e}")
logger.debug(traceback.format_exc())
raise HTTPException(
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
detail="데이터베이스 연결에 문제가 발생했습니다.",
)
except Exception as e:
logger.error(f"[API Error] {func.__name__}: {e}")
logger.error(traceback.format_exc())
print(f"[API Error] {func.__name__}: {e}")
logger.debug(traceback.format_exc())
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=error_message,
@@ -263,17 +259,8 @@ def handle_api_exceptions(
def _get_handler(status: int, detail: str):
# Define
def handler(request: Request, exception: Exception) -> Response:
# DEBUG PRINT STATEMENT 👇
from rich import print, panel
print(
panel.Panel(
exception.__class__.__name__,
title="Handled Exception",
border_style="red",
),
)
# DEBUG PRINT STATEMENT 👆
logger.debug(f"Handled Exception: {exception.__class__.__name__}")
# Raise HTTPException with given status and detail
# can return JSONResponse as well
raise HTTPException(