add logger
This commit is contained in:
1 parent
1acd8846ab
commit
bf7b53c8e8
41 files changed
+1832
-694
No files matched your search
@@ -32,9 +32,11 @@ from app.song.schemas.song_schema import (
|
||||
PollingSongResponse,
|
||||
SongListItem,
|
||||
)
|
||||
from app.utils.logger import get_logger
|
||||
from app.utils.pagination import PaginatedResponse
|
||||
from app.utils.suno import SunoService
|
||||
|
||||
logger = get_logger("song")
|
||||
|
||||
router = APIRouter(prefix="/song", tags=["song"])
|
||||
|
||||
@@ -99,7 +101,7 @@ async def generate_song(
|
||||
from app.database.session import AsyncSessionLocal
|
||||
|
||||
request_start = time.perf_counter()
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] START - task_id: {task_id}, "
|
||||
f"genre: {request_body.genre}, language: {request_body.language}"
|
||||
)
|
||||
@@ -124,7 +126,7 @@ async def generate_song(
|
||||
project = project_result.scalar_one_or_none()
|
||||
|
||||
if not project:
|
||||
print(f"[generate_song] Project NOT FOUND - task_id: {task_id}")
|
||||
logger.warning(f"[generate_song] Project NOT FOUND - task_id: {task_id}")
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"task_id '{task_id}'에 해당하는 Project를 찾을 수 없습니다.",
|
||||
@@ -141,7 +143,7 @@ async def generate_song(
|
||||
lyric = lyric_result.scalar_one_or_none()
|
||||
|
||||
if not lyric:
|
||||
print(f"[generate_song] Lyric NOT FOUND - task_id: {task_id}")
|
||||
logger.warning(f"[generate_song] Lyric NOT FOUND - task_id: {task_id}")
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"task_id '{task_id}'에 해당하는 Lyric을 찾을 수 없습니다.",
|
||||
@@ -149,7 +151,7 @@ async def generate_song(
|
||||
lyric_id = lyric.id
|
||||
|
||||
query_time = time.perf_counter()
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] Queries completed - task_id: {task_id}, "
|
||||
f"project_id: {project_id}, lyric_id: {lyric_id}, "
|
||||
f"elapsed: {(query_time - request_start)*1000:.1f}ms"
|
||||
@@ -174,7 +176,7 @@ async def generate_song(
|
||||
song_id = song.id
|
||||
|
||||
stage1_time = time.perf_counter()
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] Stage 1 DONE - Song saved - "
|
||||
f"task_id: {task_id}, song_id: {song_id}, "
|
||||
f"elapsed: {(stage1_time - request_start)*1000:.1f}ms"
|
||||
@@ -184,7 +186,7 @@ async def generate_song(
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
print(
|
||||
logger.error(
|
||||
f"[generate_song] Stage 1 EXCEPTION - "
|
||||
f"task_id: {task_id}, error: {type(e).__name__}: {e}"
|
||||
)
|
||||
@@ -203,7 +205,7 @@ async def generate_song(
|
||||
suno_task_id: str | None = None
|
||||
|
||||
try:
|
||||
print(f"[generate_song] Stage 2 START - Suno API - task_id: {task_id}")
|
||||
logger.info(f"[generate_song] Stage 2 START - Suno API - task_id: {task_id}")
|
||||
suno_service = SunoService()
|
||||
suno_task_id = await suno_service.generate(
|
||||
prompt=request_body.lyrics,
|
||||
@@ -211,14 +213,14 @@ async def generate_song(
|
||||
)
|
||||
|
||||
stage2_time = time.perf_counter()
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] Stage 2 DONE - task_id: {task_id}, "
|
||||
f"suno_task_id: {suno_task_id}, "
|
||||
f"elapsed: {(stage2_time - stage2_start)*1000:.1f}ms"
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(
|
||||
logger.error(
|
||||
f"[generate_song] Stage 2 EXCEPTION - Suno API failed - "
|
||||
f"task_id: {task_id}, error: {type(e).__name__}: {e}"
|
||||
)
|
||||
@@ -244,7 +246,7 @@ async def generate_song(
|
||||
# 3단계: suno_task_id 업데이트 (새 세션으로 빠르게 처리)
|
||||
# ==========================================================================
|
||||
stage3_start = time.perf_counter()
|
||||
print(f"[generate_song] Stage 3 START - DB update - task_id: {task_id}")
|
||||
logger.info(f"[generate_song] Stage 3 START - DB update - task_id: {task_id}")
|
||||
|
||||
try:
|
||||
async with AsyncSessionLocal() as update_session:
|
||||
@@ -258,11 +260,11 @@ async def generate_song(
|
||||
|
||||
stage3_time = time.perf_counter()
|
||||
total_time = stage3_time - request_start
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] Stage 3 DONE - task_id: {task_id}, "
|
||||
f"elapsed: {(stage3_time - stage3_start)*1000:.1f}ms"
|
||||
)
|
||||
print(
|
||||
logger.info(
|
||||
f"[generate_song] SUCCESS - task_id: {task_id}, "
|
||||
f"suno_task_id: {suno_task_id}, "
|
||||
f"total_time: {total_time*1000:.1f}ms"
|
||||
@@ -277,7 +279,7 @@ async def generate_song(
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(
|
||||
logger.error(
|
||||
f"[generate_song] Stage 3 EXCEPTION - "
|
||||
f"task_id: {task_id}, error: {type(e).__name__}: {e}"
|
||||
)
|
||||
@@ -341,12 +343,12 @@ async def get_song_status(
|
||||
Azure Blob Storage에 업로드한 뒤 Song 테이블의 status를 completed로,
|
||||
song_result_url을 Blob URL로 업데이트합니다.
|
||||
"""
|
||||
print(f"[get_song_status] START - suno_task_id: {suno_task_id}")
|
||||
logger.info(f"[get_song_status] START - suno_task_id: {suno_task_id}")
|
||||
try:
|
||||
suno_service = SunoService()
|
||||
result = await suno_service.get_task_status(suno_task_id)
|
||||
parsed_response = suno_service.parse_status_response(result)
|
||||
print(f"[get_song_status] Suno API response - suno_task_id: {suno_task_id}, status: {parsed_response.status}")
|
||||
logger.info(f"[get_song_status] Suno API response - suno_task_id: {suno_task_id}, status: {parsed_response.status}")
|
||||
|
||||
# SUCCESS 상태인 경우 첫 번째 클립 정보를 DB에 직접 저장
|
||||
if parsed_response.status == "SUCCESS" and parsed_response.clips:
|
||||
@@ -354,7 +356,7 @@ async def get_song_status(
|
||||
first_clip = parsed_response.clips[0]
|
||||
audio_url = first_clip.audio_url
|
||||
clip_duration = first_clip.duration
|
||||
print(f"[get_song_status] Using first clip - id: {first_clip.id}, audio_url: {audio_url}, duration: {clip_duration}")
|
||||
logger.debug(f"[get_song_status] Using first clip - id: {first_clip.id}, audio_url: {audio_url}, duration: {clip_duration}")
|
||||
|
||||
if audio_url:
|
||||
# suno_task_id로 Song 조회
|
||||
@@ -373,17 +375,17 @@ async def get_song_status(
|
||||
if clip_duration is not None:
|
||||
song.duration = clip_duration
|
||||
await session.commit()
|
||||
print(f"[get_song_status] Song updated - suno_task_id: {suno_task_id}, status: completed, song_result_url: {audio_url}, duration: {clip_duration}")
|
||||
logger.info(f"[get_song_status] Song updated - suno_task_id: {suno_task_id}, status: completed, song_result_url: {audio_url}, duration: {clip_duration}")
|
||||
elif song and song.status == "completed":
|
||||
print(f"[get_song_status] SKIPPED - Song already completed, suno_task_id: {suno_task_id}")
|
||||
logger.info(f"[get_song_status] SKIPPED - Song already completed, suno_task_id: {suno_task_id}")
|
||||
|
||||
print(f"[get_song_status] SUCCESS - suno_task_id: {suno_task_id}")
|
||||
logger.info(f"[get_song_status] SUCCESS - suno_task_id: {suno_task_id}")
|
||||
return parsed_response
|
||||
|
||||
except Exception as e:
|
||||
import traceback
|
||||
|
||||
print(f"[get_song_status] EXCEPTION - suno_task_id: {suno_task_id}, error: {e}")
|
||||
logger.error(f"[get_song_status] EXCEPTION - suno_task_id: {suno_task_id}, error: {e}")
|
||||
return PollingSongResponse(
|
||||
success=False,
|
||||
status="error",
|
||||
@@ -438,7 +440,7 @@ async def download_song(
|
||||
session: AsyncSession = Depends(get_session),
|
||||
) -> DownloadSongResponse:
|
||||
"""task_id로 Song 상태를 polling하고 completed 시 Project 정보와 노래 URL을 반환합니다."""
|
||||
print(f"[download_song] START - task_id: {task_id}")
|
||||
logger.info(f"[download_song] START - task_id: {task_id}")
|
||||
try:
|
||||
# task_id로 Song 조회 (여러 개 있을 경우 가장 최근 것 선택)
|
||||
song_result = await session.execute(
|
||||
@@ -450,7 +452,7 @@ async def download_song(
|
||||
song = song_result.scalar_one_or_none()
|
||||
|
||||
if not song:
|
||||
print(f"[download_song] Song NOT FOUND - task_id: {task_id}")
|
||||
logger.warning(f"[download_song] Song NOT FOUND - task_id: {task_id}")
|
||||
return DownloadSongResponse(
|
||||
success=False,
|
||||
status="not_found",
|
||||
@@ -458,11 +460,11 @@ async def download_song(
|
||||
error_message="Song not found",
|
||||
)
|
||||
|
||||
print(f"[download_song] Song found - task_id: {task_id}, status: {song.status}")
|
||||
logger.info(f"[download_song] Song found - task_id: {task_id}, status: {song.status}")
|
||||
|
||||
# processing 상태인 경우
|
||||
if song.status == "processing":
|
||||
print(f"[download_song] PROCESSING - task_id: {task_id}")
|
||||
logger.info(f"[download_song] PROCESSING - task_id: {task_id}")
|
||||
return DownloadSongResponse(
|
||||
success=True,
|
||||
status="processing",
|
||||
@@ -472,7 +474,7 @@ async def download_song(
|
||||
|
||||
# failed 상태인 경우
|
||||
if song.status == "failed":
|
||||
print(f"[download_song] FAILED - task_id: {task_id}")
|
||||
logger.warning(f"[download_song] FAILED - task_id: {task_id}")
|
||||
return DownloadSongResponse(
|
||||
success=False,
|
||||
status="failed",
|
||||
@@ -487,7 +489,7 @@ async def download_song(
|
||||
)
|
||||
project = project_result.scalar_one_or_none()
|
||||
|
||||
print(f"[download_song] COMPLETED - task_id: {task_id}, song_result_url: {song.song_result_url}")
|
||||
logger.info(f"[download_song] COMPLETED - task_id: {task_id}, song_result_url: {song.song_result_url}")
|
||||
return DownloadSongResponse(
|
||||
success=True,
|
||||
status="completed",
|
||||
@@ -502,7 +504,7 @@ async def download_song(
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f"[download_song] EXCEPTION - task_id: {task_id}, error: {e}")
|
||||
logger.error(f"[download_song] EXCEPTION - task_id: {task_id}, error: {e}")
|
||||
return DownloadSongResponse(
|
||||
success=False,
|
||||
status="error",
|
||||
@@ -550,7 +552,7 @@ async def get_songs(
|
||||
pagination: PaginationParams = Depends(get_pagination_params),
|
||||
) -> PaginatedResponse[SongListItem]:
|
||||
"""완료된 노래 목록을 페이지네이션하여 반환합니다."""
|
||||
print(f"[get_songs] START - page: {pagination.page}, page_size: {pagination.page_size}")
|
||||
logger.info(f"[get_songs] START - page: {pagination.page}, page_size: {pagination.page_size}")
|
||||
try:
|
||||
offset = (pagination.page - 1) * pagination.page_size
|
||||
|
||||
@@ -622,14 +624,14 @@ async def get_songs(
|
||||
page_size=pagination.page_size,
|
||||
)
|
||||
|
||||
print(
|
||||
logger.info(
|
||||
f"[get_songs] SUCCESS - total: {total}, page: {pagination.page}, "
|
||||
f"page_size: {pagination.page_size}, items_count: {len(items)}"
|
||||
)
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
print(f"[get_songs] EXCEPTION - error: {e}")
|
||||
logger.error(f"[get_songs] EXCEPTION - error: {e}")
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"노래 목록 조회에 실패했습니다: {str(e)}",
|
||||
|
||||
Reference in new issue
Block a user