From: E.Smith <31170571+azlm8t@users.noreply.github.com> Date: Thu, 4 Oct 2018 17:07:33 +0000 (+0100) Subject: fanart: Tidy logging in Python script. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fc0a5401dc305cbab86a98169c6b8c6061fda6d;p=thirdparty%2Ftvheadend.git fanart: Tidy logging in Python script. We want to avoid logging stack traces unless the user explicitly enables debug, otherwise we get tracebacks whenever user does not specify an apikey for a module they do not wish to use (but have not disabled). --- diff --git a/lib/py/tvh/tv_meta_tmdb.py b/lib/py/tvh/tv_meta_tmdb.py index f6597ffcd..936b6277e 100755 --- a/lib/py/tvh/tv_meta_tmdb.py +++ b/lib/py/tvh/tv_meta_tmdb.py @@ -38,7 +38,7 @@ class Tv_meta_tmdb(object): def __init__(self, args): if args is None or "key" not in args or args["key"] is None or args["key"] == "": - logging.critical("Need a tmdb-key") + logging.critical("Need a tmdb-key. No lookup available with this module.") raise RuntimeError("Need a tmdb key"); self.tmdb_key = args["key"] self.base_url = "https://api.themoviedb.org/3/" if 'base-url' not in args else args['base-url'] diff --git a/lib/py/tvh/tv_meta_tvdb.py b/lib/py/tvh/tv_meta_tvdb.py index 2643e98f0..59da74877 100755 --- a/lib/py/tvh/tv_meta_tvdb.py +++ b/lib/py/tvh/tv_meta_tvdb.py @@ -54,7 +54,7 @@ Exceptions are thrown to indicate data could not be retrieved. logging.info(args) for arg in (["key"]): if args is None or arg not in args or args[arg] is None or args[arg] == "": - logging.critical("Need a tvdb-" + arg) + logging.critical("Need a tvdb-" + arg + ". No lookup available with this module.") raise RuntimeError("Need a tvdb-" + arg); self.languages = "en" diff --git a/support/tvhmeta b/support/tvhmeta index 106a6e633..898866a5c 100755 --- a/support/tvhmeta +++ b/support/tvhmeta @@ -35,6 +35,7 @@ import urllib import logging import glob +import traceback # Python3 decided to rename things and break compatibility... try: import urllib.parse @@ -257,7 +258,7 @@ class TvhMeta(object): obj = obj_fn(module_init_args) client_objects[module] = obj except Exception as e: - logging.exception("Failed to import and create module %s: %s" % (module, e)) + logging.info("Failed to import and create module %s: %s" % (module, e)) raise else: obj = client_objects[module] @@ -282,15 +283,18 @@ class TvhMeta(object): else: logging.info("Got poster %s and fanart %s so will try and get more artwork from other providers (if any)" % (poster, fanart)) except Exception as e: - logging.info("Lookup failed for title %s year %s in language %s with error %s", title, year, lang, e) + # Only include a traceback in debug mode, otherwise it + # clutters the text if user runs it without api keys. + extraText = " with error " + traceback.format_exc() if logging.root.isEnabledFor(logging.DEBUG) else "" + logging.info("Lookup failed with module %s for uuid %s title %s year %s in language %s%s", module, uuid, title, year, lang, extraText) # And continue to next language - if art is None: - logging.error("Lookup completely failed for title %s year %s", title, year) - raise KeyError("Lookup completely failed for title %s year %s", title, year) + if poster is None and fanart is None: + logging.error("Lookup completely failed for uuid %s title %s year %s", uuid, title, year) + raise KeyError("Lookup completely failed for uuid {} title {} year {}".format(uuid, title, year)) # Got map of fanart, poster - logging.info("Lookup success for title %s year %s with results %s", title, year, art) + logging.info("Lookup success for uuid %s title %s year %s with results poster: %s fanart: %s", uuid, title, year, poster, fanart) if poster is None and fanart is None: logging.info("No artwork found") else: