v0.0.7 | Change logging from print to logger
All checks were successful
Build And Test / build-and-push (push) Successful in 35s
All checks were successful
Build And Test / build-and-push (push) Successful in 35s
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
# nhn_prj/middleware.py
|
# nhn_prj/middleware.py
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import sys
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -16,22 +15,20 @@ class RequestLoggingMiddleware:
|
|||||||
# 요청 시작 시간
|
# 요청 시작 시간
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
|
|
||||||
# 표준출력으로 직접 출력
|
# 요청 정보 로깅
|
||||||
print(
|
logger.info(
|
||||||
f"[REQUEST] {request.method} {request.path} "
|
f"[REQUEST] {request.method} {request.path} "
|
||||||
f"| Host: {request.get_host()} "
|
f"| Host: {request.get_host()} "
|
||||||
f"| IP: {self.get_client_ip(request)}",
|
f"| IP: {self.get_client_ip(request)}"
|
||||||
file=sys.stdout,
|
|
||||||
flush=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# 헤더 로깅 (디버깅용)
|
# NHN 헤더 로깅
|
||||||
nhn_headers = {
|
nhn_headers = {
|
||||||
k: v for k, v in request.headers.items()
|
k: v for k, v in request.headers.items()
|
||||||
if k.lower().startswith('x-nhn')
|
if k.lower().startswith('x-nhn')
|
||||||
}
|
}
|
||||||
if nhn_headers:
|
if nhn_headers:
|
||||||
print(f"[HEADERS] NHN Headers: {nhn_headers}", file=sys.stdout, flush=True)
|
logger.info(f"[HEADERS] NHN Headers: {nhn_headers}")
|
||||||
|
|
||||||
# 응답 처리
|
# 응답 처리
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
@ -40,12 +37,10 @@ class RequestLoggingMiddleware:
|
|||||||
duration = time.time() - start_time
|
duration = time.time() - start_time
|
||||||
|
|
||||||
# 응답 정보 로깅
|
# 응답 정보 로깅
|
||||||
print(
|
logger.info(
|
||||||
f"[RESPONSE] {request.method} {request.path} "
|
f"[RESPONSE] {request.method} {request.path} "
|
||||||
f"| Status: {response.status_code} "
|
f"| Status: {response.status_code} "
|
||||||
f"| Duration: {duration:.3f}s",
|
f"| Duration: {duration:.3f}s"
|
||||||
file=sys.stdout,
|
|
||||||
flush=True
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
Reference in New Issue
Block a user