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

Release files for django-json-logger 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-json-logger 0.1.1
File Size Uploaded
django_json_logger-0.1.1.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-json-logger 0.1.1
File Interpreter ABI Platform
django_json_logger-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / django_json_logger-0.1.1.tar.gz

Download URL django_json_logger-0.1.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7a21de4197314ff0423f2535ab00d23b47befee9576295c61ada9b6e7ec333bd
BLAKE2b-256 checksum
How to use checksums
f065c99b6388619efef388bc0341ea6b9bfbf9f24485e98f76445ac56ad7bb99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / django_json_logger-0.1.1-py3-none-any.whl

Download URL django_json_logger-0.1.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31638f6271dd9b9f66afd101ed959f987dca798c0c6ebd6edd2cdb94d862accc
BLAKE2b-256 checksum
How to use checksums
97610e1361b3c2ef1f91f46738932a1b570ae27d5a29ef135ba04efd3f7fca35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page