diff options
| author | 2020-03-16 23:20:15 -0400 | |
|---|---|---|
| committer | 2020-03-16 23:20:15 -0400 | |
| commit | e8cc000750de972384f2f34d02d42222b4018ae9 (patch) | |
| tree | 26eb0bacedff7480d29bafcf184ca529cf9f1d9f /gallery_dl/output.py | |
| parent | 4366125d2580982abb57bc65a26fc1fb8ef2a5df (diff) | |
New upstream version 1.13.2upstream/1.13.2
Diffstat (limited to 'gallery_dl/output.py')
| -rw-r--r-- | gallery_dl/output.py | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/gallery_dl/output.py b/gallery_dl/output.py index 38e2f60..f084950 100644 --- a/gallery_dl/output.py +++ b/gallery_dl/output.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2015-2019 Mike Fährmann +# Copyright 2015-2020 Mike Fährmann # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -81,6 +81,36 @@ def initialize_logging(loglevel): return logging.getLogger("gallery-dl") +def configure_logging(loglevel): + root = logging.getLogger() + minlevel = loglevel + + # stream logging handler + handler = root.handlers[0] + opts = config.interpolate(("output",), "log") + if opts: + if isinstance(opts, str): + opts = {"format": opts} + if handler.level == LOG_LEVEL and "level" in opts: + handler.setLevel(opts["level"]) + if "format" in opts or "format-date" in opts: + handler.setFormatter(Formatter( + opts.get("format", LOG_FORMAT), + opts.get("format-date", LOG_FORMAT_DATE), + )) + if minlevel > handler.level: + minlevel = handler.level + + # file logging handler + handler = setup_logging_handler("logfile", lvl=loglevel) + if handler: + root.addHandler(handler) + if minlevel > handler.level: + minlevel = handler.level + + root.setLevel(minlevel) + + def setup_logging_handler(key, fmt=LOG_FORMAT, lvl=LOG_LEVEL): """Setup a new logging handler""" opts = config.interpolate(("output",), key) @@ -112,22 +142,6 @@ def setup_logging_handler(key, fmt=LOG_FORMAT, lvl=LOG_LEVEL): return handler -def configure_logging_handler(key, handler): - """Configure a logging handler""" - opts = config.interpolate(("output",), key) - if not opts: - return - if isinstance(opts, str): - opts = {"format": opts} - if handler.level == LOG_LEVEL and "level" in opts: - handler.setLevel(opts["level"]) - if "format" in opts or "format-date" in opts: - handler.setFormatter(Formatter( - opts.get("format", LOG_FORMAT), - opts.get("format-date", LOG_FORMAT_DATE), - )) - - # -------------------------------------------------------------------- # Utility functions |
