From 2029264a433da9818eaa153561c800251870596b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= <sybren@stuvel.eu> Date: Wed, 23 Aug 2017 09:45:14 +0200 Subject: [PATCH] Added `--debug` CLI parameter to enable debug logging This makes it easier to enable debug logging, as it doesn't require editing `flamenco-worker.cfg`. --- CHANGELOG.md | 2 ++ flamenco_worker/cli.py | 6 +++++- flamenco_worker/config.py | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11d554ba..ed911e41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ changed functionality, fixed bugs). ## Version 2.0.8 (in development) - Fixed parsing of `--config` CLI param on Python 3.5 +- Added `--debug` CLI parameter to easily enable debug logging without having + to edit `flamenco-worker.cfg`. ## Version 2.0.7 (released 2017-07-04) diff --git a/flamenco_worker/cli.py b/flamenco_worker/cli.py index 5ab4e487..b44673fc 100644 --- a/flamenco_worker/cli.py +++ b/flamenco_worker/cli.py @@ -20,12 +20,16 @@ def main(): help="Erases authentication information and re-registers this worker " "at the Manager. WARNING: this can cause duplicate worker information " "in the Manager's database.") + parser.add_argument('-d', '--debug', action='store_true', + help="Enables debug logging for Flamenco Worker's own log entries. " + "Edit the logging config in flamenco-worker.cfg " + "for more powerful options.") args = parser.parse_args() # Load configuration from . import config confparser = config.load_config(args.config, args.verbose) - config.configure_logging(confparser) + config.configure_logging(confparser, enable_debug=args.debug) log = logging.getLogger(__name__) log.debug('Starting') diff --git a/flamenco_worker/config.py b/flamenco_worker/config.py index c85c2c03..bb809f56 100644 --- a/flamenco_worker/config.py +++ b/flamenco_worker/config.py @@ -116,8 +116,12 @@ def load_config(config_file: pathlib.Path = None, return confparser -def configure_logging(confparser: configparser.ConfigParser): +def configure_logging(confparser: configparser.ConfigParser, enable_debug: bool): import logging.config logging.config.fileConfig(confparser, disable_existing_loggers=True) logging.captureWarnings(capture=True) + + if enable_debug: + logging.getLogger('flamenco_worker').setLevel(logging.DEBUG) + log.debug('Enabling debug logging') -- GitLab