fix: suppress task related archive logs
This commit is contained in:
parent
73b8d867a0
commit
ee8218764f
3 changed files with 23 additions and 2 deletions
|
|
@ -266,7 +266,12 @@ def extract_info_sync(
|
|||
params["verbose"] = True
|
||||
params.pop("quiet", None)
|
||||
|
||||
log_wrapper = LogWrapper()
|
||||
suppress: tuple[str, ...] = ()
|
||||
patterns = kwargs.get("suppress_logs")
|
||||
if isinstance(patterns, list | tuple):
|
||||
suppress = tuple(value for value in patterns if isinstance(value, str) and value)
|
||||
|
||||
log_wrapper = LogWrapper(suppress=suppress)
|
||||
id_dict: dict[str, str | None] = get_archive_id(url=url)
|
||||
archive_id: str | None = f".{id_dict['id']}" if id_dict.get("id") else None
|
||||
logger_name: str = f"yt-dlp{archive_id or '.extract_info'}"
|
||||
|
|
|
|||
|
|
@ -86,8 +86,9 @@ class LogTarget:
|
|||
|
||||
|
||||
class LogWrapper:
|
||||
def __init__(self):
|
||||
def __init__(self, suppress: list[str] | tuple[str, ...] | None = None):
|
||||
self.targets: list[LogTarget] = []
|
||||
self.suppress: tuple[str, ...] = tuple(value for value in (suppress or ()) if isinstance(value, str) and value)
|
||||
|
||||
def add_target(self, target: logging.Logger | Callable, level: int = logging.DEBUG, name: str | None = None):
|
||||
"""
|
||||
|
|
@ -118,7 +119,13 @@ class LogWrapper:
|
|||
def has_targets(self):
|
||||
return len(self.targets) > 0
|
||||
|
||||
def _skip(self, msg: Any) -> bool:
|
||||
return isinstance(msg, str) and any(value in msg for value in self.suppress)
|
||||
|
||||
def _log(self, level, msg, *args, **kwargs):
|
||||
if self._skip(msg):
|
||||
return
|
||||
|
||||
for target in self.targets:
|
||||
if level < target.level:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -51,6 +51,14 @@ def _get_ignored_conditions(extras: dict | None) -> list[str]:
|
|||
return ignored
|
||||
|
||||
|
||||
def _task_ignored_logs(item: "Item") -> list[str] | None:
|
||||
extras = item.extras if isinstance(item.extras, dict) else {}
|
||||
if not extras.get("source_handler"):
|
||||
return None
|
||||
|
||||
return ["has already been recorded in the archive"]
|
||||
|
||||
|
||||
async def add_item(
|
||||
queue: "DownloadQueue",
|
||||
entry: dict,
|
||||
|
|
@ -209,6 +217,7 @@ async def add(
|
|||
follow_redirect=True,
|
||||
capture_logs=logging.WARNING,
|
||||
budget_sleep=True,
|
||||
suppress_logs=_task_ignored_logs(item),
|
||||
)
|
||||
|
||||
if not entry:
|
||||
|
|
|
|||
Loading…
Reference in a new issue