Logging Formatter for colorizing logs per thread, process, logger name, or any record attribute
Project description
color_bucket_logger
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file color_bucket_logger-0.2.0.tar.gz
.
File metadata
- Download URL: color_bucket_logger-0.2.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93192233f18f9181ce4b9de6b69823792a7401d9d7a3cef47a48e26074c4bfc9 |
|
MD5 | 59346eb4294d8611e05653c6d3e92661 |
|
BLAKE2b-256 | f603cec53f0b2ce1a360fc0fd4fd5c8373db46c64bb72bea75f8db249c8bb8da |
File details
Details for the file color_bucket_logger-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: color_bucket_logger-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd0006b8ac35b3e11472eaa5b68ab6ef5b09525d083bb048a9c47ba1f20ec1f4 |
|
MD5 | 5f1396a739163c7f9c79886d9b5b478c |
|
BLAKE2b-256 | ef8926841bbe26c8c3286003b9d8f0f7ec7f2f1dd9f28cc99e51d1b838a0c5c6 |