Skip to main content

A Django app to logging in json format.

Project description

Description

This library provides the ability of converting django logs to JSON.

Installation

Using standard Json library:

pip install git+https://github.com/missterr/django-json-logging.git

Custom json libraries

Orjson

To use Orjson:

pip install git+https://github.com/missterr/django-json-logging.git#egg=django-json-logging[orjson]

and add to Django settings LOGGING_SERIALIZER="orjson"

Ujson

To use Ujson:

pip install git+https://github.com/missterr/django-json-logging.git#egg=django-json-logging[ujson]

and add to Django settings LOGGING_SERIALIZER="ujson"

Note: If you're using zsh you need to escape square brackets: pip install ... [ujson]

Usage

Django setup

# setting.py

LOGGING_APP_NAME = 'your_app_name'  # required
LOGGING_FIELDS = ('levelname', 'name', 'module', 'process', 'thread', 'pathname', 'asctime')

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'json': {
            '()': 'django_json_logging.formatters.JSONFormatter',
        },
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'json',
        },
    },
    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'WARNING',
        },
        'django': {
            'handlers': ['console'],
            'level': 'WARNING',
            'propagate': False,
        },
    },
}

Somewhere in the code

import logging

your_json_logger = logging.getLogger('json_logger')
your_json_logger.warning('Something happened here', extra={'event_code': 'xxx'})

Exhaustive fields list can be found here

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

django-json-logger-0.1.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

django_json_logger-0.1.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

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