[output] add 'Logger.traceback()' helper

This commit is contained in:
Mike Fährmann
2025-10-14 18:44:29 +02:00
parent 9d054ad18d
commit 8c62be343e
15 changed files with 33 additions and 27 deletions

View File

@@ -95,7 +95,7 @@ class HttpDownloader(DownloaderBase):
except Exception as exc:
if self.downloading:
output.stderr_write("\n")
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
raise
finally:
# remove file from incomplete downloads

View File

@@ -49,7 +49,7 @@ class YoutubeDLDownloader(DownloaderBase):
except (ImportError, SyntaxError) as exc:
self.log.error("Cannot import module '%s'",
getattr(exc, "name", ""))
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.download = lambda u, p: False
return False
@@ -91,7 +91,7 @@ class YoutubeDLDownloader(DownloaderBase):
else:
info_dict = self._extract_info(ytdl_instance, url)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning("%s: %s", exc.__class__.__name__, exc)
if not info_dict:
@@ -164,7 +164,7 @@ class YoutubeDLDownloader(DownloaderBase):
try:
ytdl_instance.process_info(info_dict)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
return False
pathfmt.temppath = info_dict.get("filepath") or info_dict["_filename"]
@@ -188,7 +188,7 @@ class YoutubeDLDownloader(DownloaderBase):
ytdl_instance.process_info(entry)
status = True
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.error("%s: %s", exc.__class__.__name__, exc)
return status

View File

@@ -211,7 +211,7 @@ class CivitaiExtractor(Extractor):
try:
return self.api.image_generationdata(image["id"])
except Exception as exc:
return self.log.debug("", exc_info=exc)
return self.log.traceback(exc)
def _extract_meta_post(self, image):
try:
@@ -220,7 +220,7 @@ class CivitaiExtractor(Extractor):
post["publishedAt"], "%Y-%m-%dT%H:%M:%S.%fZ")
return post
except Exception as exc:
return self.log.debug("", exc_info=exc)
return self.log.traceback(exc)
def _extract_meta_version(self, item, is_post=True):
try:
@@ -228,7 +228,7 @@ class CivitaiExtractor(Extractor):
version = self.api.model_version(version_id).copy()
return version.pop("model", None), version
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
return None, None
def _extract_version_id(self, item, is_post=True):

View File

@@ -404,7 +404,7 @@ class DeviantartExtractor(Extractor):
try:
return self._tiptap_to_html(markup)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.error("%s: '%s: %s'", deviation["index"],
exc.__class__.__name__, exc)

View File

@@ -79,7 +79,7 @@ class FanslyExtractor(Extractor):
try:
self._extract_attachment(files, post, attachment)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.error(
"%s/%s, Failed to extract media (%s: %s)",
post["id"], attachment.get("id"),

View File

@@ -38,7 +38,7 @@ class FlickrExtractor(Extractor):
self.log.warning(
"Skipping photo %s (%s: %s)",
photo["id"], exc.__class__.__name__, exc)
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
else:
photo.update(data)
url = self._file_url(photo)

View File

@@ -68,7 +68,7 @@ class IssuuUserExtractor(IssuuBase, Extractor):
data = text.extr(html, '\\"docs\\":', '}]\\n"]')
docs = util.json_loads(data.replace('\\"', '"'))
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
return
for publication in docs:

View File

@@ -58,7 +58,7 @@ class NewgroundsExtractor(Extractor):
post = self.extract_post(post_url)
url = post.get("url")
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
url = None
if url:

View File

@@ -46,7 +46,7 @@ class PinterestExtractor(Extractor):
try:
files = self._extract_files(pin)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning(
"%s: Error when extracting download URLs (%s: %s)",
pin.get("id"), exc.__class__.__name__, exc)

View File

@@ -149,7 +149,7 @@ class PixivExtractor(Extractor):
self._extract_ajax(work, body)
return self._extract_ugoira(work, url)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning(
"%s: Unable to extract Ugoira URL. Provide "
"logged-in cookies to access it", work["id"])
@@ -453,7 +453,7 @@ class PixivArtworksExtractor(PixivExtractor):
ajax_ids.extend(map(int, body["manga"]))
ajax_ids.sort()
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning("u%s: Failed to collect artwork IDs "
"using AJAX API", self.user_id)
else:

View File

@@ -214,7 +214,7 @@ class TiktokUserExtractor(TiktokExtractor):
except (ImportError, SyntaxError) as exc:
self.log.error("Cannot import module '%s'",
getattr(exc, "name", ""))
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
raise exception.ExtractionError("yt-dlp or youtube-dl is required "
"for this feature!")

View File

@@ -146,7 +146,7 @@ class TwitterExtractor(Extractor):
self._extract_media(
data, data["extended_entities"]["media"], files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning(
"%s: Error while extracting media files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)
@@ -155,7 +155,7 @@ class TwitterExtractor(Extractor):
try:
self._extract_card(tweet, files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning(
"%s: Error while extracting Card files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)
@@ -164,7 +164,7 @@ class TwitterExtractor(Extractor):
try:
self._extract_twitpic(data, files)
except Exception as exc:
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
self.log.warning(
"%s: Error while extracting TwitPic files (%s: %s)",
data["id_str"], exc.__class__.__name__, exc)

View File

@@ -157,16 +157,17 @@ class Job():
raise
pass
except exception.AbortExtraction as exc:
log.traceback(exc)
log.error(exc.message)
self.status |= exc.code
except (exception.TerminateExtraction, exception.RestartExtraction):
raise
except exception.GalleryDLException as exc:
log.error("%s: %s", exc.__class__.__name__, exc)
log.debug("", exc_info=exc)
log.traceback(exc)
self.status |= exc.code
except OSError as exc:
log.debug("", exc_info=exc)
log.traceback(exc)
if (name := exc.__class__.__name__) == "JSONDecodeError":
log.error("Failed to parse JSON data: %s: %s", name, exc)
self.status |= 1
@@ -179,7 +180,7 @@ class Job():
"copy its output and report this issue on "
"https://github.com/mikf/gallery-dl/issues ."),
exc.__class__.__name__, exc)
log.debug("", exc_info=exc)
log.traceback(exc)
self.status |= 1
except BaseException:
self.status |= 1
@@ -690,9 +691,9 @@ class DownloadJob(Job):
try:
pp_obj = pp_cls(self, pp_dict)
except Exception as exc:
pp_log.traceback(exc)
pp_log.error("'%s' initialization failed: %s: %s",
name, exc.__class__.__name__, exc)
pp_log.debug("", exc_info=exc)
else:
pp_list.append(pp_obj)

View File

@@ -89,6 +89,11 @@ class LoggerAdapter():
self.logger = logger
self.extra = job._logger_extra
def traceback(self, exc):
if self.logger.isEnabledFor(logging.DEBUG):
self.logger._log(
logging.DEBUG, "", None, exc_info=exc, extra=self.extra)
def debug(self, msg, *args, **kwargs):
if self.logger.isEnabledFor(logging.DEBUG):
kwargs["extra"] = self.extra

View File

@@ -151,7 +151,7 @@ class UgoiraPP(PostProcessor):
"%s: Unable to extract frames from %s (%s: %s)",
pathfmt.kwdict.get("id"), pathfmt.filename,
exc.__class__.__name__, exc)
return self.log.debug("", exc_info=exc)
return self.log.traceback(exc)
if self.convert(pathfmt, tempdir):
if self.delete:
@@ -227,12 +227,12 @@ class UgoiraPP(PostProcessor):
output.stderr_write("\n")
self.log.error("Unable to invoke FFmpeg (%s: %s)",
exc.__class__.__name__, exc)
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
pathfmt.realpath = pathfmt.temppath
except Exception as exc:
output.stderr_write("\n")
self.log.error("%s: %s", exc.__class__.__name__, exc)
self.log.debug("", exc_info=exc)
self.log.traceback(exc)
pathfmt.realpath = pathfmt.temppath
else:
if self.mtime: