mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Add logging handler.
This commit is contained in:
parent
4ed9120ae9
commit
a3720c0645
5 changed files with 60 additions and 14 deletions
32
pre_commit/logging_handler.py
Normal file
32
pre_commit/logging_handler.py
Normal 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(),
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue