forked from pre-commit/pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging_handler.py
More file actions
39 lines (29 loc) · 906 Bytes
/
logging_handler.py
File metadata and controls
39 lines (29 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import unicode_literals
import logging
from pre_commit import color
from pre_commit import output
logger = logging.getLogger('pre_commit')
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):
output.write_line(
'{} {}'.format(
color.format_color(
'[{}]'.format(record.levelname),
LOG_LEVEL_COLORS[record.levelname],
self.use_color,
),
record.getMessage(),
),
)
def add_logging_handler(*args, **kwargs):
logger.addHandler(LoggingHandler(*args, **kwargs))
logger.setLevel(logging.INFO)