diff --git a/docs/configuration.rst b/docs/configuration.rst index 7d3152bd..571cd879 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -72,6 +72,7 @@ Description Controls whether the output strings should be shortened to fit on one console line. =========== ===== + output.progress --------------- =========== ===== @@ -89,6 +90,15 @@ Description Controls the progress indicator when *gallery-dl* is run with =========== ===== +output.logfile +-------------- +=========== ===== +Type ``string`` +Default ``null`` +Description File to write logging output to. +=========== ===== + + Downloader Options ================== diff --git a/docs/gallery-dl.conf b/docs/gallery-dl.conf index 46b10532..99af3ff7 100644 --- a/docs/gallery-dl.conf +++ b/docs/gallery-dl.conf @@ -127,6 +127,7 @@ { "mode": "auto", "shorten": true, - "progress": true + "progress": true, + "logfile": null, } } diff --git a/gallery_dl/__init__.py b/gallery_dl/__init__.py index 49a0ff33..3a5ff5aa 100644 --- a/gallery_dl/__init__.py +++ b/gallery_dl/__init__.py @@ -21,7 +21,7 @@ if sys.hexversion < 0x3030000: sys.exit(1) import logging -from . import version, config, option, extractor, job, exception +from . import version, config, option, extractor, job, util, exception __version__ = version.__version__ log = logging.getLogger("gallery-dl") @@ -108,6 +108,21 @@ def main(): except AttributeError: pass + # logfile + logfile = config.interpolate(("output", "logfile")) + if logfile: + try: + handler = logging.FileHandler(util.expand_path(logfile)) + except OSError as exc: + log.warning("logfile: %s", exc) + else: + formatter = logging.Formatter( + "[%(asctime)s][%(name)s][%(levelname)s] %(message)s", + "%Y-%m-%d %H:%M:%S") + handler.setFormatter(formatter) + handler.setLevel(logging.INFO) + logging.getLogger().addHandler(handler) + if args.list_modules: for module_name in extractor.modules: print(module_name) diff --git a/gallery_dl/option.py b/gallery_dl/option.py index ec638237..29e3c9dc 100644 --- a/gallery_dl/option.py +++ b/gallery_dl/option.py @@ -93,12 +93,6 @@ def build_parser(): metavar="FILE", action=ConfigAction, dest="cookies", help="File to load additional cookies from", ) - general.add_argument( - "--write-unsupported", - metavar="FILE", dest="unsupportedfile", - help=("Write URLs, which get emitted by other extractors but cannot " - "be handled, to FILE"), - ) output = parser.add_argument_group("Output Options") output.add_argument( @@ -133,6 +127,17 @@ def build_parser(): help=("Print a list of extractor classes " "with description, (sub)category and example URL"), ) + output.add_argument( + "--write-log", + metavar="FILE", dest="logfile", action=ConfigAction, + help=("Write logging output to FILE"), + ) + output.add_argument( + "--write-unsupported", + metavar="FILE", dest="unsupportedfile", + help=("Write URLs, which get emitted by other extractors but cannot " + "be handled, to FILE"), + ) downloader = parser.add_argument_group("Downloader Options") downloader.add_argument(