logging_stream_colorer

Module: tools.logging_stream_colorer

This module contains a class to change the color of the logger output.

It has to be used with the logger class.

Example of usage:

# Custom logger class with multiple destinations
class ColoredLogger(logging.Logger):
    FORMAT = "[$BOLD%(name)-20s$RESET][%(levelname)-18s]  %(message)s ($BOLD%(filename)s$RESET:%(lineno)d)"
    COLOR_FORMAT = formatter_message(FORMAT, True)
    
    def __init__(self, name):
        logging.Logger.__init__(self, name, logging.DEBUG)

        color_formatter = ColoredFormatter(self.COLOR_FORMAT)

        console = logging.StreamHandler()
        console.setFormatter(color_formatter)

        self.addHandler(console)
        return


logging.setLoggerClass(ColoredLogger)

Adopted version of http://stackoverflow.com/questions/384076/how-can-i-make-the-python-logging-output-to-be-colored . This is distributed under creative commons: http://creativecommons.org/licenses/by-sa/3.0/

Author:Hendrik Woehrle (hendrik.woehrle@dfki.de)
Created:2011/03/22

Inheritance diagram for pySPACE.tools.logging_stream_colorer:

Inheritance diagram of pySPACE.tools.logging_stream_colorer

Class Summary

COLORS
ColoredLevelFormatter(msg[, use_color])
ColorFormatter(msg[, color])

Function Summary

formatter_message(message[, use_color])

Classes

COLORS

class pySPACE.tools.logging_stream_colorer.COLORS[source]
BLACK = 0
BLUE = 4
CYAN = 6
GREEN = 2
MAGENTA = 5
RED = 1
WHITE = 7
YELLOW = 3

ColoredLevelFormatter

class pySPACE.tools.logging_stream_colorer.ColoredLevelFormatter(msg, use_color=True)[source]

Bases: logging.Formatter

__init__(msg, use_color=True)[source]
format(record)[source]

ColorFormatter

class pySPACE.tools.logging_stream_colorer.ColorFormatter(msg, color=7)[source]

Bases: logging.Formatter

__init__(msg, color=7)[source]
format(record)[source]

Function

formatter_message()

pySPACE.tools.logging_stream_colorer.formatter_message(message, use_color=True)[source]