Files
mayan-edms/mayan/apps/common/log.py
Roberto Rosario 7e5aad7714 Backport color log formatter
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
2019-10-27 16:11:16 -04:00

24 lines
628 B
Python

from __future__ import unicode_literals
import logging
from django.utils.termcolors import colorize
PALETTE = {
'CRITICAL': {'fg': 'red', 'opts': ('bold', 'blink', 'reverse')},
'DEBUG': {'fg': 'cyan'},
'ERROR': {'fg': 'red', 'opts': ('bold',)},
'INFO': {'fg': 'white'},
'SUCCESS': {'fg': 'green'},
'WARNING': {'fg': 'yellow', 'opts': ('bold', 'underscore')},
}
class ColorFormatter(logging.Formatter):
def format(self, record):
record.msg = colorize(
text=record.msg, **PALETTE.get(record.levelname, {})
)
return super(ColorFormatter, self).format(record)