From 0dd9ff0ec9a91e5a81cd5a30651287cad32f8ab0 Mon Sep 17 00:00:00 2001 From: Pierre Mdawar Date: Thu, 16 Apr 2020 15:54:56 +0300 Subject: [PATCH] Accept lowercase logging level names and accept tuples when setting exception handlers (#1233) * Accept lowercase logging level names * Accept both lists and tuples when setting Worker exception_handlers --- rq/logutils.py | 4 +++- rq/worker.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rq/logutils.py b/rq/logutils.py index 2d849c1..324553b 100644 --- a/rq/logutils.py +++ b/rq/logutils.py @@ -20,7 +20,9 @@ def setup_loghandlers(level=None, date_format=DEFAULT_LOGGING_DATE_FORMAT, logger.addHandler(handler) if level is not None: - logger.setLevel(level) + # The level may be a numeric value (e.g. when using the logging module constants) + # Or a string representation of the logging level + logger.setLevel(level if isinstance(level, int) else level.upper()) def _has_effective_handler(logger): diff --git a/rq/worker.py b/rq/worker.py index 50d1733..7e090f5 100644 --- a/rq/worker.py +++ b/rq/worker.py @@ -210,7 +210,7 @@ class Worker(object): self.disable_default_exception_handler = disable_default_exception_handler - if isinstance(exception_handlers, list): + if isinstance(exception_handlers, (list, tuple)): for handler in exception_handlers: self.push_exc_handler(handler) elif exception_handlers is not None: