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

+3 -8
View File
@@ -1,15 +1,15 @@
import asyncio
import json
import logging
import re
import aiohttp
import bs4
from app.utils.logger import get_logger
from config import crawler_settings
# 로거 설정
logger = logging.getLogger(__name__)
logger = get_logger("scraper")
class GraphQLException(Exception):
@@ -109,7 +109,7 @@ query getAccommodation($id: String!, $deviceType: String) {
self.scrap_type = "GraphQL"
except GraphQLException:
print("fallback")
logger.debug("GraphQL failed, fallback to Playwright")
self.scrap_type = "Playwright"
pass # 나중에 pw 이용한 crawling으로 fallback 추가
@@ -138,7 +138,6 @@ query getAccommodation($id: String!, $deviceType: String) {
try:
logger.info(f"[NvMapScraper] Requesting place_id: {place_id}")
print(f"[NvMapScraper] Requesting place_id: {place_id}")
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.post(
@@ -148,24 +147,20 @@ query getAccommodation($id: String!, $deviceType: String) {
) as response:
if response.status == 200:
logger.info(f"[NvMapScraper] SUCCESS - place_id: {place_id}")
print(f"[NvMapScraper] SUCCESS - place_id: {place_id}")
return await response.json()
# 실패 상태 코드
logger.error(f"[NvMapScraper] Failed with status {response.status} - place_id: {place_id}")
print(f"[NvMapScraper] 실패 상태 코드: {response.status}")
raise GraphQLException(
f"Request failed with status {response.status}"
)
except (TimeoutError, asyncio.TimeoutError):
logger.error(f"[NvMapScraper] Timeout - place_id: {place_id}")
print(f"[NvMapScraper] Timeout - place_id: {place_id}")
raise CrawlingTimeoutException(f"Request timed out after {self.REQUEST_TIMEOUT}s")
except aiohttp.ClientError as e:
logger.error(f"[NvMapScraper] Client error: {e}")
print(f"[NvMapScraper] Client error: {e}")
raise GraphQLException(f"Client error: {e}")
async def _get_facility_string(self, place_id: str) -> str | None: