Skip to main content

Logging Formatter for colorizing logs per thread, process, logger name, or any record attribute

Project description

color_bucket_logger

https://img.shields.io/pypi/v/color_bucket_logger.svg https://img.shields.io/travis/alikins/color_bucket_logger.svg Documentation Status Updates

Python logging Formatter for colorizing logs per thread, process, logger name, or any record attribute

Using this logging formatter to make log records that share a common attribute share a color automatically.

For example, a process with three threads could show the log entries for each thread in a different color. The same can be done per process, or per logger name. Any log record attribute can be used to choose the color used for the log entry.

The entire log record, the particular log field (‘level’ or ‘process’ for ex.), or a group of fields can be colorized based on an attribute value.

For example, the fields for ‘thread’, ‘threadName’, ‘process’, ‘processName’ could be colorized based on the thread id.

Usage

Examples

Basic config colorized by logger name:

import logging

import color_bucket_logger

log = logging.getLogger('example')
log.setLevel(logging.DEBUG)

log_format = '%(asctime)s %(process)s %(levelname)s %(name)s %(funcName)s -- %(message)s'

# Use logger name for the primary color of each entry
formatter = color_bucket_logger.ColorFormatter(fmt=log_format, default_color_by_attr='name')

handler = logging.StreamHandler()
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)

# basicConfig will add our handler to the root logger
# Note 'handlers' arg is py3 only
logging.basicConfig(level=logging.DEBUG, handlers=[handler])

Color Group Examples

Example uses of color_groups:

# color almost everything by logger name
color_groups = [('name', ['filename', 'module', 'lineno', 'funcName', 'pathname'])]

color_groups = [
    ('process', ['default', 'message']),
    ('process', ['processName', 'process']),
    ('thread', ['default', 'threadName', 'message', 'unset', 'processName', 'exc_text']),
    ('thread', ['threadName', 'thread']),
    ]

# color logger name, filename and lineno same as the funcName
color_groups = [('funcName', ['default', 'message', 'unset', 'name', 'filename', 'lineno'])]

# color message same as debug level
color_groups = [('levelname', ['levelname', 'levelno'])]

# color funcName, filename, lineno same as logger name
color_groups = [('name', ['funcName', 'filename', 'lineno'])]

# color groups can be based on non standard 'extra' attributes or log record
# attibutes created from filters. In this example, a 'task' attributes.
color_groups = [('task', ['task_uuid', 'task'])]

# color default, msg and playbook/play/task by the play
color_groups = [('play', ['default','message', 'unset', 'play', 'task'])]

License

  • Free software: MIT license

Features

  • TODO

History

0.2.0 (2019-05-30)

  • Prep for release

0.1.0 (2017-06-15)

  • First release on PyPI.

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

color_bucket_logger-0.2.0.tar.gz (27.8 kB view hashes)

Uploaded Source

Built Distribution

color_bucket_logger-0.2.0-py2.py3-none-any.whl (16.0 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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