Skip to content

Commit

Permalink
colorful logging
Browse files Browse the repository at this point in the history
  • Loading branch information
quantmind committed Sep 23, 2013
1 parent a634d75 commit 0ef9bc9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ examples/webmail/config.py
.htmlprof
examples/djangoapp/test.db
test.pid
pulsar.egg-info
extensions/src/cparser.cpp
6 changes: 5 additions & 1 deletion pulsar/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ def configure_logging(self, logger=None, config=None, level=None,
'white': WHITE}

class ColoredStream(logging.StreamHandler):
bold = True
COLORS = {"DEBUG": "cyan",
"WARNING": "yellow",
"WARNING": "magenta",
"ERROR": "red",
"CRITICAL": "red",
"INFO": "green"}
Expand Down Expand Up @@ -277,6 +278,8 @@ def color(self, record):
handle = GetStdHandle(-11)
oldcolors = GetConsoleInfo(handle).wAttributes
code |= (oldcolors & 0x00F0)
if self.bold:
code |= FOREGROUND_INTENSITY
SetConsoleTextAttribute(handle, code)
while len(text) > 32768:
file.write(text[:32768])
Expand Down Expand Up @@ -318,6 +321,7 @@ class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
('dwMaximumWindowSize', COORD)]

WHITE = 0x0007
FOREGROUND_INTENSITY = 0x0008
COLOURS = {'red': 0x0004 ,
'green': 0x0002,
'yellow': 0x0006,
Expand Down

0 comments on commit 0ef9bc9

Please sign in to comment.