summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelwin Ong <selwin.ong@gmail.com>2020-07-31 11:03:03 +0700
committerGitHub <noreply@github.com>2020-07-31 11:03:03 +0700
commit265e4b76ab7668508d1f1d4768ebc3d9d372b73a (patch)
tree07bf38e9b44222169606ffc5a07e6bea8661e5c7
parent5cee02d83f2c50d083b8b43f805c75c7b4e0d73c (diff)
downloadrq-265e4b76ab7668508d1f1d4768ebc3d9d372b73a.tar.gz
log messages < error is now output to stdout instead of stderr (#1312)
-rw-r--r--rq/logutils.py8
-rw-r--r--rq/worker.py2
2 files changed, 8 insertions, 2 deletions
diff --git a/rq/logutils.py b/rq/logutils.py
index 324553b..5759a11 100644
--- a/rq/logutils.py
+++ b/rq/logutils.py
@@ -3,6 +3,7 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals)
import logging
+import sys
from rq.utils import ColorizingStreamHandler
from rq.defaults import (DEFAULT_LOGGING_FORMAT,
@@ -15,9 +16,14 @@ def setup_loghandlers(level=None, date_format=DEFAULT_LOGGING_DATE_FORMAT,
if not _has_effective_handler(logger):
formatter = logging.Formatter(fmt=log_format, datefmt=date_format)
- handler = ColorizingStreamHandler()
+ handler = ColorizingStreamHandler(stream=sys.stdout)
handler.setFormatter(formatter)
+ handler.addFilter(lambda record: record.levelno < logging.ERROR)
+ error_handler = ColorizingStreamHandler(stream=sys.stderr)
+ error_handler.setFormatter(formatter)
+ error_handler.addFilter(lambda record: record.levelno >= logging.ERROR)
logger.addHandler(handler)
+ logger.addHandler(error_handler)
if level is not None:
# The level may be a numeric value (e.g. when using the logging module constants)
diff --git a/rq/worker.py b/rq/worker.py
index 6868f75..bae12f1 100644
--- a/rq/worker.py
+++ b/rq/worker.py
@@ -974,7 +974,7 @@ class Worker(object):
def handle_exception(self, job, *exc_info):
"""Walks the exception handler stack to delegate exception handling."""
exc_string = Worker._get_safe_exception_string(
- traceback.format_exception_only(*exc_info[:2]) + traceback.format_exception(*exc_info)
+ traceback.format_exception(*exc_info)
)
self.log.error(exc_string, exc_info=True, extra={
'func': job.func_name,