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.

Source Distribution

coloredlogs-0.1.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file coloredlogs-0.1.tar.gz.

File metadata

  • Download URL: coloredlogs-0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for coloredlogs-0.1.tar.gz
Algorithm Hash digest
SHA256 896d42e4e461b65cc697457efa0957e955f147355ca0fae6011a737940c6d773
MD5 cb601dd8ca258afaf371507214d61302
BLAKE2b-256 e6b5ade6b22ad99c54d4c985a54c148d94340dc59b3804b0da92e97a94988338

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page