author | Radek Brich <radek.brich@devl.cz> |
Tue, 19 Mar 2013 16:46:36 +0100 | |
changeset 79 | d02a36d0a9b0 |
parent 78 | 64c62ac8f65d |
permissions | -rw-r--r-- |
13
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
import logging |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
from pgtoolkit import highlight |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
|
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
class ColoredFormatter(logging.Formatter): |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
def __init__(self, fmt, datefmt): |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
logging.Formatter.__init__(self, fmt, datefmt) |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
def format(self, record): |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
color = () |
78
64c62ac8f65d
Rename config module to configparser.
Radek Brich <radek.brich@devl.cz>
parents:
13
diff
changeset
|
12 |
if record.levelno == logging.ERROR and record.exc_info is not None: |
13
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
color = (11, 1) |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
if color: |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
origmsg = record.msg |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
f,b = color |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
record.msg = highlight(1, f, b) + record.msg + highlight(0) |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
res = logging.Formatter.format(self, record) |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
record.msg = origmsg |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
else: |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
res = logging.Formatter.format(self, record) |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
return res |
16dc5dec9c36
ToolBase: add -d parameter, which triggers debug mode (print SQL queries).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |