Skip to content

Commit

Permalink
add option to write logging output to a file
Browse files Browse the repository at this point in the history
- '--write-log FILE' as cmdline argument
- 'output.logfile' as config file option
  • Loading branch information
mikf committed Jan 26, 2018
1 parent f94e370 commit 97f4f15
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 10 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Description Controls whether the output strings should be shortened to fit
on one console line.
=========== =====


output.progress
---------------
=========== =====
Expand All @@ -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
==================

Expand Down
3 changes: 2 additions & 1 deletion docs/gallery-dl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
{
"mode": "auto",
"shorten": true,
"progress": true
"progress": true,
"logfile": null,
}
}
17 changes: 16 additions & 1 deletion gallery_dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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")
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 11 additions & 6 deletions gallery_dl/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 97f4f15

Please sign in to comment.