From 92fb787a69278c1e6cd8c0848b1e76556514ad3f Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Fri, 4 Jul 2014 17:41:34 +0700 Subject: [PATCH 1/2] Only add logging handler if nothing is configured. --- rq/logutils.py | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/rq/logutils.py b/rq/logutils.py index ff87337..a5c1d9f 100644 --- a/rq/logutils.py +++ b/rq/logutils.py @@ -11,32 +11,15 @@ try: except ImportError: from rq.compat.dictconfig import dictConfig # noqa +from rq.utils import ColorizingStreamHandler -def setup_loghandlers(level=None): - if not logging._handlers: - dictConfig({ - 'version': 1, - 'disable_existing_loggers': False, - - 'formatters': { - 'console': { - 'format': '%(asctime)s %(message)s', - 'datefmt': '%H:%M:%S', - }, - }, - 'handlers': { - 'console': { - 'level': 'DEBUG', - # 'class': 'logging.StreamHandler', - 'class': 'rq.utils.ColorizingStreamHandler', - 'formatter': 'console', - 'exclude': ['%(asctime)s'], - }, - }, - - 'root': { - 'handlers': ['console'], - 'level': level or 'INFO', - } - }) +def setup_loghandlers(level=None): + logger = logging.getLogger() + if not logger.handlers: + logger.setLevel(level) + formatter = logging.Formatter(fmt='%(asctime)s %(message)s', + datefmt='%H:%M:%S') + handler = ColorizingStreamHandler() + handler.setFormatter(formatter) + logger.addHandler(handler) From b828078dde8cdc57f66f5333af497af6da8fd2e4 Mon Sep 17 00:00:00 2001 From: Selwin Ong Date: Mon, 7 Jul 2014 19:46:55 +0700 Subject: [PATCH 2/2] Fixed default logging level in setup_loghandlers. --- rq/logutils.py | 4 ++-- rq/scripts/rqworker.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/rq/logutils.py b/rq/logutils.py index a5c1d9f..2a23ae2 100644 --- a/rq/logutils.py +++ b/rq/logutils.py @@ -14,8 +14,8 @@ except ImportError: from rq.utils import ColorizingStreamHandler -def setup_loghandlers(level=None): - logger = logging.getLogger() +def setup_loghandlers(level='INFO'): + logger = logging.getLogger('rq.worker') if not logger.handlers: logger.setLevel(level) formatter = logging.Formatter(fmt='%(asctime)s %(message)s', diff --git a/rq/scripts/rqworker.py b/rq/scripts/rqworker.py index 01850dd..d01dff9 100644 --- a/rq/scripts/rqworker.py +++ b/rq/scripts/rqworker.py @@ -17,8 +17,6 @@ from rq.scripts import (add_standard_arguments, read_config_file, setup_default_arguments, setup_redis) from rq.utils import import_attribute -logger = logging.getLogger(__name__) - def parse_args(): parser = argparse.ArgumentParser(description='Starts an RQ worker.')