This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

logformatjson is a library that provides a simple JSON formatter for the standard python logging package. It allows for nested arbitrary metadata to be inserted at instantiation and run time. The library is opionanted but attempts to allow most opinions to be overridden.

warning: This library is under active development. The log format and API are expected to change.

Install

  • via pip:
pip install logformatjson

Examples

  1. basic usage - JSONFormatter can be set on any handler as your would expect:
import logging
import sys
from logformatjson import JSONFormatter

LOGGER = logging.getLogger()
LOGGER.setLevel(logging.DEBUG)
log_handler = logging.StreamHandler(sys.stdout)
log_handler.setFormatter(JSONFormatter())
LOGGER.addHandler(log_handler)

LOGGER.debug('this is my debug message', extra={'some_key': 'important_value'})

which produces the following json (from ipython):

{
  "timestamp": "2016-02-19T19:39:17.061886",
  "message": "this is my debug message",
  "levelname": "DEBUG",
  "metadata": {
    "filename": "test.py",
    "funcName": "<module>",
    "extra": {
      "some_key": "important_value"
    },
    "log_type": "python",
    "lineno": 11,
    "module": "test",
    "pathname": "test.py"
  },
  "log_version": "1.0"
}
  1. Adding an additional metadata in every log entry:

log_handler.setFormatter(JSONFormatter(metadata={'application_version': '1.0.0'}))

  1. Overriding the defaults at instantiation:

    • Override attributes copied or skipped from the LogRecord:
      
      log_handler.setFormatter(JSONFormatter(kept_attrs= ['created', ]))
      log_handler.setFormatter(JSONFormatter(skipped_attrs= ['filename', ]))
      
      
    • Override the provided json encoder:

      def my_json_encoder(obj):
        return int(obj)
      
      
      log_handler.setFormatter(JSONFormatter(json_encoder = my_json_encoder))
      
      
  2. Override the defaults at runtime:

    • Log type (intended to be mixed with extra fields):

      
      logger.debug('GET / HTTP/1.1', log_type='HTTP'}
      
      
  3. Extra fields:

    
    LOGGER.debug('this is my debug message', extra={'some_key': 'important_value'})
    
    

Tests

Tests can be run via make:

make lint
make test

Authors

Release History

Release History

0.1.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.0.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
logformatjson-0.1.0.tar.gz (4.7 kB) Copy SHA256 Checksum SHA256 Source Mar 10, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting