将 TMDB 及网络重试日志的输出调整为 DEBUG 级别

- tmdb_service 中主/备地址失败与切换日志改为 debug
- run.py 设置 urllib3/requests 日志级别为 ERROR
- 为 urllib3.connectionpool 添加过滤器,自动将 “Retrying (...)” 告警降为 DEBUG
This commit is contained in:
x1ao4 2025-09-22 23:37:34 +08:00
parent 06b6ab04d4
commit f7371b660b
3 changed files with 30 additions and 9 deletions

View File

@ -586,6 +586,27 @@ logging.basicConfig(
format="[%(asctime)s][%(levelname)s] %(message)s",
datefmt="%m-%d %H:%M:%S",
)
# 降低第三方网络库的重试噪音:将 urllib3/requests 的日志调为 ERROR并把“Retrying ...”消息降级为 DEBUG
try:
logging.getLogger("urllib3").setLevel(logging.ERROR)
logging.getLogger("requests").setLevel(logging.ERROR)
class _RetryWarningToDebug(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
try:
msg = str(record.getMessage())
if "Retrying (Retry(" in msg or "Retrying (" in msg:
# 将此条记录的等级降到 DEBUG
record.levelno = logging.DEBUG
record.levelname = "DEBUG"
except Exception:
pass
return True
_urllib3_logger = logging.getLogger("urllib3.connectionpool")
_urllib3_logger.addFilter(_RetryWarningToDebug())
except Exception:
pass
# 过滤werkzeug日志输出
if not DEBUG:
logging.getLogger("werkzeug").setLevel(logging.ERROR)

View File

@ -41,7 +41,7 @@ class TMDBService:
def reset_to_primary_url(self):
"""重置到主API地址"""
self.current_url = self.primary_url
logger.info("TMDB API地址已重置为主地址")
logger.debug("TMDB API地址已重置为主地址")
def get_current_api_url(self) -> str:
"""获取当前使用的API地址"""
@ -87,17 +87,17 @@ class TMDBService:
pass
return data
except Exception as e:
logger.warning(f"TMDB主地址请求失败: {e}")
logger.debug(f"TMDB主地址请求失败: {e}")
# 如果当前使用的是主地址,尝试切换到备用地址
if self.current_url == self.primary_url:
logger.info("尝试切换到TMDB备用地址...")
logger.debug("尝试切换到TMDB备用地址...")
self.current_url = self.backup_url
try:
url = f"{self.current_url}{endpoint}"
response = self.session.get(url, params=params, timeout=10)
response.raise_for_status()
logger.info("TMDB备用地址连接成功")
logger.debug("TMDB备用地址连接成功")
data = response.json()
try:
self._cache[cache_key] = (_now(), data)
@ -111,7 +111,7 @@ class TMDBService:
return None
else:
# 如果备用地址也失败,重置回主地址
logger.error(f"TMDB备用地址请求失败: {e}")
logger.debug(f"TMDB备用地址请求失败: {e}")
self.current_url = self.primary_url
return None
@ -186,7 +186,7 @@ class TMDBService:
return original_title
except Exception as e:
logger.warning(f"获取中文标题失败: {e}, 使用原始标题: {original_title}")
logger.debug(f"获取中文标题失败: {e}, 使用原始标题: {original_title}")
return original_title
def get_tv_show_episodes(self, tv_id: int, season_number: int) -> Optional[Dict]:
@ -458,7 +458,7 @@ class TMDBService:
if poster_path:
return poster_path
except Exception as e:
logger.warning(f"获取原始语言海报失败: {e}")
logger.debug(f"获取原始语言海报失败: {e}")
# 如果设置为中文或原始语言获取失败,尝试中文海报
if self.poster_language == "zh-CN" or self.poster_language == "original":
@ -477,7 +477,7 @@ class TMDBService:
if poster_path:
return poster_path
except Exception as e:
logger.warning(f"获取中文海报失败: {e}")
logger.debug(f"获取中文海报失败: {e}")
# 如果都失败了,返回默认海报路径
return details.get('poster_path', '')

View File

@ -1886,7 +1886,7 @@
<div class="input-group-prepend">
<span class="input-group-text">名称筛选</span>
</div>
<input type="text" class="form-control" v-model="calendar.nameFilter" placeholder="任务名称或剧集名称关键词">
<input type="text" class="form-control" v-model="calendar.nameFilter" placeholder="任务或节目名称关键词">
<div class="input-group-append">
<button type="button" class="btn btn-outline-secondary filter-btn-square" @click="clearCalendarFilter('nameFilter')"><i class="bi bi-x-lg"></i></button>
</div>