Skip to content

Latest commit

 

History

History
108 lines (70 loc) · 2.21 KB

README.rst

File metadata and controls

108 lines (70 loc) · 2.21 KB

Nice Log

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

Quick usage

Since version 0.3, nicelog comes with a helper function to quickly set up logging for basic needs.

from nicelog import setup_logging

setup_logging()

Or, if you want to include debug messages too:

setup_logging(debug=True)

Advanced 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,
}