comparison rhodecode/lib/colored_formatter.py @ 547:1e757ac98988

renamed project to rhodecode
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 06 Oct 2010 03:18:16 +0200
parents pylons_app/lib/colored_formatter.py@779dabcaae28
children b9ea10d3e419 73434499fa72
comparison
equal deleted inserted replaced
546:7c2f5e4d7bbf 547:1e757ac98988
1
2 import logging
3
4 BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
5
6 # Sequences
7 RESET_SEQ = "\033[0m"
8 COLOR_SEQ = "\033[1;%dm"
9 BOLD_SEQ = "\033[1m"
10
11 COLORS = {
12 'CRITICAL': MAGENTA, # level 50
13 'ERROR': RED, # level 40
14 'WARNING': CYAN, # level 30
15 'INFO': GREEN, # level 20
16 'DEBUG': BLUE, # level 10
17 }
18
19 class ColorFormatter(logging.Formatter):
20
21 def __init__(self, *args, **kwargs):
22 # can't do super(...) here because Formatter is an old school class
23 logging.Formatter.__init__(self, *args, **kwargs)
24
25 def format(self, record):
26 """
27 Changes record's levelname to use with COLORS enum
28 """
29
30 levelname = record.levelname
31 start = COLOR_SEQ % (COLORS[levelname])
32 def_record = logging.Formatter.format(self, record)
33 end = RESET_SEQ
34
35 colored_record = start + def_record + end
36 return colored_record
37
38 logging.ColorFormatter = ColorFormatter