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>
This commit is contained in:
@@ -193,6 +193,7 @@ class CommonApp(MayanAppConfig):
|
|||||||
'disable_existing_loggers': False,
|
'disable_existing_loggers': False,
|
||||||
'formatters': {
|
'formatters': {
|
||||||
'intermediate': {
|
'intermediate': {
|
||||||
|
'()': 'mayan.apps.common.log.ColorFormatter',
|
||||||
'format': '%(name)s <%(process)d> [%(levelname)s] "%(funcName)s() line %(lineno)d %(message)s"',
|
'format': '%(name)s <%(process)d> [%(levelname)s] "%(funcName)s() line %(lineno)d %(message)s"',
|
||||||
},
|
},
|
||||||
'logfile': {
|
'logfile': {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
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)
|
||||||
Reference in New Issue
Block a user