##// END OF EJS Templates
Removed bolds from colored logs (better readability)
marcink -
r1391:5f80cc29 beta
parent child Browse files
Show More
@@ -1,85 +1,85 b''
1
1
2 import logging
2 import logging
3
3
4 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
4 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
5
5
6 # Sequences
6 # Sequences
7 RESET_SEQ = "\033[0m"
7 RESET_SEQ = "\033[0m"
8 COLOR_SEQ = "\033[1;%dm"
8 COLOR_SEQ = "\033[0;%dm"
9 BOLD_SEQ = "\033[1m"
9 BOLD_SEQ = "\033[1m"
10
10
11 COLORS = {
11 COLORS = {
12 'CRITICAL': MAGENTA,
12 'CRITICAL': MAGENTA,
13 'ERROR': RED,
13 'ERROR': RED,
14 'WARNING': CYAN,
14 'WARNING': CYAN,
15 'INFO': GREEN,
15 'INFO': GREEN,
16 'DEBUG': BLUE,
16 'DEBUG': BLUE,
17 'SQL': YELLOW
17 'SQL': YELLOW
18 }
18 }
19
19
20
20
21 def one_space_trim(s):
21 def one_space_trim(s):
22 if s.find(" ") == -1:
22 if s.find(" ") == -1:
23 return s
23 return s
24 else:
24 else:
25 s = s.replace(' ', ' ')
25 s = s.replace(' ', ' ')
26 return one_space_trim(s)
26 return one_space_trim(s)
27
27
28
28
29 def format_sql(sql):
29 def format_sql(sql):
30 sql = sql.replace('\n', '')
30 sql = sql.replace('\n', '')
31 sql = one_space_trim(sql)
31 sql = one_space_trim(sql)
32 sql = sql\
32 sql = sql\
33 .replace(',', ',\n\t')\
33 .replace(',', ',\n\t')\
34 .replace('SELECT', '\n\tSELECT \n\t')\
34 .replace('SELECT', '\n\tSELECT \n\t')\
35 .replace('UPDATE', '\n\tUPDATE \n\t')\
35 .replace('UPDATE', '\n\tUPDATE \n\t')\
36 .replace('DELETE', '\n\tDELETE \n\t')\
36 .replace('DELETE', '\n\tDELETE \n\t')\
37 .replace('FROM', '\n\tFROM')\
37 .replace('FROM', '\n\tFROM')\
38 .replace('ORDER BY', '\n\tORDER BY')\
38 .replace('ORDER BY', '\n\tORDER BY')\
39 .replace('LIMIT', '\n\tLIMIT')\
39 .replace('LIMIT', '\n\tLIMIT')\
40 .replace('WHERE', '\n\tWHERE')\
40 .replace('WHERE', '\n\tWHERE')\
41 .replace('AND', '\n\tAND')\
41 .replace('AND', '\n\tAND')\
42 .replace('LEFT', '\n\tLEFT')\
42 .replace('LEFT', '\n\tLEFT')\
43 .replace('INNER', '\n\tINNER')\
43 .replace('INNER', '\n\tINNER')\
44 .replace('INSERT', '\n\tINSERT')\
44 .replace('INSERT', '\n\tINSERT')\
45 .replace('DELETE', '\n\tDELETE')
45 .replace('DELETE', '\n\tDELETE')
46 return sql
46 return sql
47
47
48
48
49 class ColorFormatter(logging.Formatter):
49 class ColorFormatter(logging.Formatter):
50
50
51 def __init__(self, *args, **kwargs):
51 def __init__(self, *args, **kwargs):
52 # can't do super(...) here because Formatter is an old school class
52 # can't do super(...) here because Formatter is an old school class
53 logging.Formatter.__init__(self, *args, **kwargs)
53 logging.Formatter.__init__(self, *args, **kwargs)
54
54
55 def format(self, record):
55 def format(self, record):
56 """
56 """
57 Changes record's levelname to use with COLORS enum
57 Changes record's levelname to use with COLORS enum
58 """
58 """
59
59
60 levelname = record.levelname
60 levelname = record.levelname
61 start = COLOR_SEQ % (COLORS[levelname])
61 start = COLOR_SEQ % (COLORS[levelname])
62 def_record = logging.Formatter.format(self, record)
62 def_record = logging.Formatter.format(self, record)
63 end = RESET_SEQ
63 end = RESET_SEQ
64
64
65 colored_record = ''.join([start, def_record, end])
65 colored_record = ''.join([start, def_record, end])
66 return colored_record
66 return colored_record
67
67
68
68
69 class ColorFormatterSql(logging.Formatter):
69 class ColorFormatterSql(logging.Formatter):
70
70
71 def __init__(self, *args, **kwargs):
71 def __init__(self, *args, **kwargs):
72 # can't do super(...) here because Formatter is an old school class
72 # can't do super(...) here because Formatter is an old school class
73 logging.Formatter.__init__(self, *args, **kwargs)
73 logging.Formatter.__init__(self, *args, **kwargs)
74
74
75 def format(self, record):
75 def format(self, record):
76 """
76 """
77 Changes record's levelname to use with COLORS enum
77 Changes record's levelname to use with COLORS enum
78 """
78 """
79
79
80 start = COLOR_SEQ % (COLORS['SQL'])
80 start = COLOR_SEQ % (COLORS['SQL'])
81 def_record = format_sql(logging.Formatter.format(self, record))
81 def_record = format_sql(logging.Formatter.format(self, record))
82 end = RESET_SEQ
82 end = RESET_SEQ
83
83
84 colored_record = ''.join([start, def_record, end])
84 colored_record = ''.join([start, def_record, end])
85 return colored_record
85 return colored_record
General Comments 0
You need to be logged in to leave comments. Login now