Skip to main content

Colored stream handler for the logging module

Project description

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")

Contact

If you have questions, bug reports, suggestions, etc. please send an e-mail to peter@peterodding.com. The latest version of coloredlogs will always be available on PyPi.

License

This software is licensed under the MIT license.

© 2013 Peter Odding.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for coloredlogs, version 0.1
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

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page