% python -i colorful_logging_formatter.py
>>> import logging
>>> logger = logging.getLogger('foo')
>>> logger.setLevel(logging.DEBUG)
>>> import sys
>>> handler = logging.StreamHandler(sys.stderr)
>>> handler.setFormatter(ColorLogFormatter())
>>> handler.setLevel(logging.DEBUG)
>>> logger.addHandler(handler)
>>>
>>> logger.debug('Debug message')
DEBUG foo Debug message
>>> logger.info('Info message')
INFO foo Info message
>>> logger.warning('Warning message')
WARNING foo Warning message
>>> logger.error('Error message')
ERROR foo Error message
>>> logger.critical('Critical message')
CRITICAL foo Critical message
>>> try:
... 100 / 0
... except:
... logger.exception('Something bad happened!')
...
ERROR foo Something bad happened!
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ZeroDivisionError: integer division or modulo by zero
>>>
To see it in all its glory, you'll need to use a powerline-patched font in your terminal (I use inconsolata-dz). Otherwise, just set POWERLINE_STYLE = False
.