equal
deleted
inserted
replaced
1 import logging |
|
2 |
|
3 from pgtoolkit import highlight |
|
4 |
|
5 |
|
6 class ColoredFormatter(logging.Formatter): |
|
7 def __init__(self, fmt, datefmt): |
|
8 logging.Formatter.__init__(self, fmt, datefmt) |
|
9 |
|
10 def format(self, record): |
|
11 color = () |
|
12 if record.levelno == logging.ERROR and record.exc_info is not None: |
|
13 color = (11, 1) |
|
14 if color: |
|
15 origmsg = record.msg |
|
16 f,b = color |
|
17 record.msg = highlight(1, f, b) + record.msg + highlight(0) |
|
18 res = logging.Formatter.format(self, record) |
|
19 record.msg = origmsg |
|
20 else: |
|
21 res = logging.Formatter.format(self, record) |
|
22 return res |
|
23 |
|