Skip to main content

Making logs nicer since 2015!

Project description

Making logs nicer since 2015!

Version Downloads Travis CodeCov ReadTheDocs

Installation

sprockets.logging is available on the Python Package Index and can be installed via pip or easy_install:

pip install sprockets.logging

Documentation

https://sprocketslogging.readthedocs.org

Requirements

  • No external requirements

Example

This examples demonstrates the most basic usage of sprockets.logging

import logging
import sys

import sprockets.logging


formatter = logging.Formatter('%(levelname)s %(message)s {%(context)s}')
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
handler.addFilter(sprockets.logging.ContextFilter(properties=['context']))
logging.Logger.root.addHandler(handler)
logging.Logger.root.setLevel(logging.DEBUG)

# Outputs: INFO Hi there {None}
logging.info('Hi there')

# Outputs: INFO No KeyError {bah}
logging.info('No KeyError', extra={'context': 'bah'})

# Outputs: INFO Now with context! {foo}
adapted = logging.LoggerAdapter(logging.Logger.root, extra={'context': 'foo'})
adapted.info('Now with context!')

Source

sprockets.logging source is available on Github at https://github.com/sprockets/sprockets.logging

License

sprockets.logging is released under the 3-Clause BSD license.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page