Backport color log formatter

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-10-27 16:11:16 -04:00
parent 42cfef505c
commit 7e5aad7714
3 changed files with 25 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
- Fix platformtemplate command --context option help message.
- Language translations update.
- Add target to run all translations targets.
- Backport color log formatter from branch version/next.
3.2.8 (2019-10-01)
==================

View File

@@ -164,6 +164,7 @@ class CommonApp(MayanAppConfig):
'disable_existing_loggers': False,
'formatters': {
'intermediate': {
'()': 'mayan.apps.common.log.ColorFormatter',
'format': '%(name)s <%(process)d> [%(levelname)s] "%(funcName)s() line %(lineno)d %(message)s"',
},
'logfile': {

23
mayan/apps/common/log.py Normal file
View File

@@ -0,0 +1,23 @@
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)