Colorizing Console Streams¶
ColorizingStreamHandler is a handler which allows colorizing of console
streams, described here in more detail.
A stream handler which supports colorizing of console streams under Windows, Linux and Mac OS X.
Parameters: strm – The stream to colorize - typically
Colorize a message for a logging event.
This implementation uses the
level_mapclass attribute to map the LogRecord’s level to a colour/intensity setting, which is then applied to the whole message.
- message – The message to colorize.
- record – The
LogRecordfor the message.
Formats a record for output.
This implementation colorizes the message line, but leaves any traceback unolorized.
Returns true if the handler’s stream is a terminal.
Output a colorized message.
On Linux and Mac OS X, this method just writes the already-colorized message to the stream, since on these platforms console streams accept ANSI escape sequences for colorization. On Windows, this handler implements a subset of ANSI escape sequence handling by parsing the message, extracting the sequences and making Win32 API calls to colorize the output.
Parameters: message – The message to colorize and output.