🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

django-json-logger

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-json-logger

A Django app to logging in json format.

0.1.1
PyPI
Maintainers
1

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

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts