Colored stream handler for the logging module
The ColoredStreamHandler class defined in the coloredlogs module is a simple logging handler that inherits from logging.StreamHandler but adds ANSI escape sequences to render your logging messages in color. It uses only standard colors so it should work on any UNIX terminal. Currently this module does not support non-UNIX terminals (e.g. the Windows console).
The log handler formats log messages including timestamps, logger names and severity levels. It uses ANSI escape sequences to highlight timestamps and debug messages in green and error and warning messages in red. The handler does not use ANSI escape sequences when output redirection applies, for example when the standard error stream is being redirected to a file. Here’s an example of its use:
Here’s a small demonstration of the logging handler:
# Configure your logger. import logging, coloredlogs log = logging.getLogger('your-module') log.addHandler(coloredlogs.ColoredStreamHandler()) # Some examples. log.setLevel(logging.DEBUG) log.debug("this is a debugging message") log.info("this is an informational message") log.warn("this is a warning message") log.error("this is an error message") log.fatal("this is a fatal message") log.critical("this is a critical message")
This software is licensed under the MIT license.
© 2013 Peter Odding.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size coloredlogs-0.1.tar.gz (3.3 kB)||File type Source||Python version None||Upload date||Hashes View hashes|