Skip to main content

Description

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

Installation

Using standard Json library:

pip install django-json-logger

Custom json libraries

Orjson

To use Orjson:

pip install django-json-logger[orjson]

and add to Django settings LOGGING_SERIALIZER="orjson"

Ujson

To use Ujson:

pip install django-json-logger[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

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.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_json_logger-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file django_json_logger-0.1.1.tar.gz.

File metadata

  • Download URL: django_json_logger-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for django_json_logger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7a21de4197314ff0423f2535ab00d23b47befee9576295c61ada9b6e7ec333bd
MD5 999ac5847dd1604ae74225a8c16f8949
BLAKE2b-256 f065c99b6388619efef388bc0341ea6b9bfbf9f24485e98f76445ac56ad7bb99

See more details on using hashes here.

File details

Details for the file django_json_logger-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_json_logger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31638f6271dd9b9f66afd101ed959f987dca798c0c6ebd6edd2cdb94d862accc
MD5 3c22cb1e9c4000d29ac5ca2439e3ff7b
BLAKE2b-256 97610e1361b3c2ef1f91f46738932a1b570ae27d5a29ef135ba04efd3f7fca35

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Supported by

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