-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
29 lines (24 loc) · 1022 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import sys
import logging
from django.core.management.color import color_style
class DjangoColorsFormatter(logging.Formatter):
def __init__(self, *args, **kwargs):
if sys.version_info < (2, 7):
logging.Formatter.__init__(self, *args, **kwargs)
else:
super(DjangoColorsFormatter, self).__init__(*args, **kwargs)
self.style = self.configure_style(color_style())
def configure_style(self, style):
style.DEBUG = style.HTTP_NOT_MODIFIED
style.INFO = style.HTTP_INFO
style.WARNING = style.HTTP_NOT_FOUND
style.ERROR = style.ERROR
style.CRITICAL = style.HTTP_SERVER_ERROR
return style
def format(self, record):
message = logging.Formatter.format(self, record)
if sys.version_info[0] < 3:
if isinstance(message, unicode):
message = message.encode('utf-8')
colorizer = getattr(self.style, record.levelname, self.style.HTTP_SUCCESS)
return colorizer(message)