diff --git a/pre_commit/logging_handler.py b/pre_commit/logging_handler.py index 3226b8c0..87102ca8 100644 --- a/pre_commit/logging_handler.py +++ b/pre_commit/logging_handler.py @@ -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], diff --git a/tests/logging_handler_test.py b/tests/logging_handler_test.py index 6e8d1835..63d9d21d 100644 --- a/tests/logging_handler_test.py +++ b/tests/logging_handler_test.py @@ -19,7 +19,7 @@ def test_logging_handler_color(): handler = LoggingHandler(True, print_mock) handler.emit(FakeLogRecord('hi', 'WARNING', 30)) print_mock.assert_called_once_with( - color.YELLOW + '[WARNING]' + color.NORMAL + ' hi', + color.YELLOW + '[WARNING]' + color.NORMAL + ' hi\n', ) @@ -28,5 +28,5 @@ def test_logging_handler_no_color(): handler = LoggingHandler(False, print_mock) handler.emit(FakeLogRecord('hi', 'WARNING', 30)) print_mock.assert_called_once_with( - '[WARNING] hi', + '[WARNING] hi\n', )