republisher/repub/colorlog.py
2024-04-18 11:57:24 +02:00

33 lines
832 B
Python

import copy
from colorlog import ColoredFormatter
import scrapy.utils.log
color_formatter = ColoredFormatter(
(
"%(log_color)s%(levelname)-5s%(reset)s "
"%(yellow)s[%(asctime)s]%(reset)s"
"%(white)s %(name)s %(funcName)s %(bold_purple)s:%(lineno)d%(reset)s "
"%(log_color)s%(message)s%(reset)s"
),
datefmt="%y-%m-%d %H:%M:%S",
log_colors={
"DEBUG": "blue",
"INFO": "bold_cyan",
"WARNING": "red",
"ERROR": "bg_bold_red",
"CRITICAL": "red,bg_white",
},
)
_get_handler = copy.copy(scrapy.utils.log._get_handler)
def _get_handler_custom(*args, **kwargs):
handler = _get_handler(*args, **kwargs)
handler.setFormatter(color_formatter)
return handler
def load_colorlog():
scrapy.utils.log._get_handler = _get_handler_custom