Skip to main content

Nice colorful formatters for Python logging.

Project description

CircleCI build status

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.Colorful',
    'show_date': True,
    'show_function': True,
    'show_filename': True,
    'message_inline': False,
}

Changelog

v0.2

  • More decoupling between “colorer” and “style”

  • Support for pretty tracebacks (colorful + code context + locals)

  • Added some tests

  • Python3 support via six

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.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distributions

nicelog-0.2.1-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

nicelog-0.2.1-py2-none-any.whl (11.1 kB view details)

Uploaded Python 2

File details

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

File metadata

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

File hashes

Hashes for nicelog-0.2.1.tar.gz
Algorithm Hash digest
SHA256 611cd74405b505ad5c4877e5ec59522a324232d1c4b29e5fa411b601a0212bf4
MD5 77ee7b9ec654eb8097a1f93cdc776518
BLAKE2b-256 461c6ca0865d9fe9aebf788383b621829c6d2b0c10afa83bd08248c4a3bb5d51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nicelog-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1664783db89c2337b010817fe103c5d2db5eeb8da1d3287c48adb2c8eb2f12a4
MD5 ad8a6083736a6ef472e9f970dc7d7080
BLAKE2b-256 3233d60248642c6fceab700be263ed6e42ba46f8432491f725b7488e28d8efb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nicelog-0.2.1-py2-none-any.whl
Algorithm Hash digest
SHA256 43f46b688b711f12bc12f59cb88ac4d8b088eeddbe6f8cda14ff898a6bf5a35d
MD5 0127b151ff163d1df7da500d08a29c5d
BLAKE2b-256 949f43755ee48aeea86ca7380be4093866dfa7eafaa23b4c53a2545b0296152d

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