|
|
|
@ -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)
|
|
|
|
|