Convert LoggingHandler to use sys.stdout.write

This commit is contained in:
Anthony Sottile
2014-04-13 18:36:14 -07:00
parent 3d5a360df4
commit 374ef75835
2 changed files with 7 additions and 8 deletions

View File

@@ -1,6 +1,5 @@
from __future__ import print_function
import logging
import sys
from pre_commit import color
@@ -14,14 +13,14 @@ LOG_LEVEL_COLORS = {
class LoggingHandler(logging.Handler):
def __init__(self, use_color, print_fn=print):
def __init__(self, use_color, write=sys.stdout.write):
logging.Handler.__init__(self)
self.use_color = use_color
self.__print_fn = print_fn
self.__write = write
def emit(self, record):
self.__print_fn(
u'{0}{1}'.format(
self.__write(
u'{0}{1}\n'.format(
color.format_color(
'[{0}]'.format(record.levelname),
LOG_LEVEL_COLORS[record.levelname],