Files
mayan-edms/mayan/apps/common/log.py
Roberto Rosario 59fbbd82e2 Common: Add colorized log formatter
New log formatter that color the output depending on the log
level of the message. The default palette handles: INFO,
SUCCESS, ERROR, DEBUG and CRITICAL.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-12-05 02:07:34 -04:00

23 lines
625 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)