Backport color log formatter
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -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)
|
||||
==================
|
||||
|
||||
@@ -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
23
mayan/apps/common/log.py
Normal 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)
|
||||
|
||||
Reference in New Issue
Block a user