Skip to main content

Nice colorful formatters for Python logging.

Project description

https://travis-ci.org/rshk/nicelog.svg?branch=master Latest PyPI version Number of PyPI downloads Supported Python versions Development Status License

Provide formatters to nicely display colorful logging output on the console.

Fork this project on GitHub

Right now, it contains only one formatter, coloring log lines depending on the log level and adding nice line prefixes containing logger name, but future plans are to add more formatters and allow better ways to customize them.

Installation

pip install nicelog

Example usage

import logging
import sys

from nicelog.formatters import Colorful

# Setup a logger
logger = logging.getLogger('foo')
logger.setLevel(logging.DEBUG)

# Setup a handler, writing colorful output
# to the console
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(Colorful())
handler.setLevel(logging.DEBUG)
logger.addHandler(handler)

# Now log some messages..
logger.debug('Debug message')
logger.info('Info message')
logger.warning('Warning message')
logger.error('Error message')
logger.critical('Critical message')
try:
    raise ValueError('This is an exception')
except:
    logger.exception("An error occurred")

Example output

Here it is, in all its glory:

Screenshot

The output format can be further customized, eg. if you want to reduce colorfulness or verbosity.

Integrations

Django

I usually put something like this in my (local) settings:

LOGGING['formatters']['standard'] = {
    '()': 'nicelog.formatters.ColorLineFormatter',
    'show_date': True,
    'show_function': True,
    'show_filename': True,
    'message_inline': False,
}

Changelog

v0.1.9

  • Replaced strftime(3) conversion specifiers %F and %T aren’t available on all platforms: replaced with long versions %Y-%m-%d and %H:%M:%S.

v0.1.8

  • Prevent failure in case the TERM environment variable is not set (PR #1)

v0.1.7

  • Added support for message_inline argument. If set to False, messages will be displayed on their own line (useful when enabling a lot of information)

v0.1.6

  • Added support for showing more information:

    • record date

    • file name / line number

    • module / function

v0.1.5

  • Added support for nicer colors in 256-color mode

  • Removed dependency from termcolor (now shipping better implementation)

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

nicelog-0.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distributions

nicelog-0.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

nicelog-0.2-py2-none-any.whl (11.2 kB view details)

Uploaded Python 2

File details

Details for the file nicelog-0.2.tar.gz.

File metadata

  • Download URL: nicelog-0.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for nicelog-0.2.tar.gz
Algorithm Hash digest
SHA256 1d0e6fcf7fa1123d6ecbd6901b186b4a59c47969e09a93bd6464e5cdd8fc0230
MD5 30dfafc9997af8886d136e6941437707
BLAKE2b-256 dc8fd56ac78d2253bb6fceffc7a4c5fc83fe1ca3b9939977ba97eacdf5f47540

See more details on using hashes here.

File details

Details for the file nicelog-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for nicelog-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 578bdfc09f5d8d692c508668888287c468ee25291668fda913941a201be5e142
MD5 9754cd2e71d5799af96cbf3017641a53
BLAKE2b-256 bf6e303f70e6e242957769b843929f5216349bcb19743d342f0912f44d9024ae

See more details on using hashes here.

File details

Details for the file nicelog-0.2-py2-none-any.whl.

File metadata

File hashes

Hashes for nicelog-0.2-py2-none-any.whl
Algorithm Hash digest
SHA256 d69f05b9d81a98ca71d236e47712c631f101979a80bffaa9c4741bcd6a0817e4
MD5 5f92908de5867f3445307d51da518985
BLAKE2b-256 fb61e04e26fe3f03e8ed5b59b05d46aa6116a9761ded8f26075d23788b1b89f0

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