Skip to main content

Ultimate Python colorized logger with user-custom color

Project description

https://travis-ci.org/laysakura/rainbow_logging_handler.png?branch=master

Ultimate Python colorized logger.

Quick Usage

http://github.com/laysakura/rainbow_logging_handler/raw/master/doc/screenshot.png

This script runs like above screenshot.

import sys
import logging
from rainbow_logging_handler import RainbowLoggingHandler

def main_func():
    # setup `logging` module
    logger = logging.getLogger('test_logging')
    logger.setLevel(logging.DEBUG)
    formatter = logging.Formatter("[%(asctime)s] %(name)s %(funcName)s():%(lineno)d\t%(message)s")  # same as default

    # setup `RainbowLoggingHandler`
    handler = RainbowLoggingHandler(sys.stderr, color_funcName=('black', 'yellow', True))
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    logger.debug("debug msg")
    logger.info("info msg")
    logger.warn("warn msg")
    logger.error("error msg")
    logger.critical("critical msg")

    try:
        raise RuntimeError("Opa!")
    except Exception as e:
        logger.exception(e)

if __name__ == '__main__':
    main_func()

Features

Column-by-column colored log

As apparent from above screenshot, each column of logs are differently colored. Even default coloring should make log reading easier.

User custom color

Every column colors are customizable.

formatter = logging.Formatter('%(pathname)s [%(module)s] - %(funcName)s:L%(lineno)d : %(message)s')
handler   = RainbowLoggingHandler(
    sys.stderr,
    # Customizing each column's color
    color_pathname=('black', 'red'  , True), color_module=('yellow', None, False),
    color_funcName=('blue' , 'white', True), color_lineno=('green' , None, False),
)
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.info("hello custom world")

Above code produces output like this.

http://github.com/laysakura/rainbow_logging_handler/raw/master/doc/screenshot-custom-color.png

High portability

Linux, BSD, Mac OS, and Windows are supposed to be supported.

Runs with both Python 2.6 or higher & Python 3.2 or higher.

Install

Install from PyPI

$ pip install rainbow_logging_handler

Install from Github repo

$ git clone https://github.com/laysakura/rainbow_logging_handler.git
$ cd rainbow_logging_handler
$ ./setup.py install

Author

Mikko Ohtamaa <mikko@opensourcehacker.com>, Sho Nakatani <lay.sakura@gmail.com>

And special thanks to 10sr for advice.

License

This is free and unencumbered public domain software. For more information, see <http://unlicense.org/> or the accompanying LICENSE.txt file.

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

rainbow_logging_handler-2.0.2.zip (13.5 kB view details)

Uploaded Source

File details

Details for the file rainbow_logging_handler-2.0.2.zip.

File metadata

File hashes

Hashes for rainbow_logging_handler-2.0.2.zip
Algorithm Hash digest
SHA256 87297e50bfea7011cd4dc2f13741652d858acd018ffae98fd336fd20f53c8047
MD5 eaa6b0c5e504f58972a29987682d611b
BLAKE2b-256 044f6dd733a4b43fbef7511ecc03ebc28a044f9dbe9fabc354608b6431f0dfd0

See more details on using hashes here.

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