Skip to main content

Json formatter for logging

Project description

=============
logformatjson
=============

``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 instantian and run time.

Install
=======

via ``pip``:
pip install logformatjson

Exmaples
========

1. Basic Usage:

.. code-block:: python

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):

.. code-block:: javascript

{
"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": "0.1"
}

2. Adding an additional metadata in every log entry:

.. code-block:: python


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



Tests
=====

Tests can be run via ``make``:

.. code-block:: shell
make lint
make unit

Authors
=======
* Ryan Richard <ryan@kumoru.io>

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

logformatjson-0.0.3.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file logformatjson-0.0.3.tar.gz.

File metadata

  • Download URL: logformatjson-0.0.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for logformatjson-0.0.3.tar.gz
Algorithm Hash digest
SHA256 019b16e6c92c5fd2b38a1eed0ac86176bdf614e342aa832e3e2b9221883697fc
MD5 e468d789dbf8a1744757f3d4ba178b7a
BLAKE2b-256 03ada2c3af6686ec99c3a640152eedb8cfea476db61293e7aeb6ea509f9c6d0c

See more details on using hashes here.

Supported by

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