Add logging handler.

This commit is contained in:
Anthony Sottile 2014-04-05 21:50:20 -07:00
parent 4ed9120ae9
commit a3720c0645
5 changed files with 60 additions and 14 deletions

View file

@ -0,0 +1,32 @@
from __future__ import print_function
import logging
from pre_commit import color
LOG_LEVEL_COLORS = {
'DEBUG': '',
'INFO': '',
'WARNING': color.YELLOW,
'ERROR': color.RED,
}
class LoggingHandler(logging.Handler):
def __init__(self, use_color):
super(LoggingHandler, self).__init__()
self.use_color = use_color
def emit(self, record):
print(
u'{0}{1}'.format(
color.format_color(
'[{0}]'.format(record.levelname),
LOG_LEVEL_COLORS[record.levelname],
self.use_color,
) + ' ' if record.levelno >= logging.WARNING else '',
record.getMessage(),
)
)