parent
8c61d6ea7f
commit
017d2c5c17
3 changed files with 70 additions and 7 deletions
@ -0,0 +1,22 @@ |
||||
# -*- coding: utf-8 -*- |
||||
import logging |
||||
from django.core.management.color import color_style |
||||
|
||||
|
||||
class DjangoColorsFormatter(logging.Formatter): |
||||
def __init__(self, *args, **kwargs): |
||||
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) |
||||
colorizer = getattr(self.style, record.levelname, self.style.HTTP_SUCCESS) |
||||
return colorizer(message) |
||||
Loading…
Reference in new issue