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 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'})
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
7a21de4197314ff0423f2535ab00d23b47befee9576295c61ada9b6e7ec333bd
|
|
MD5 |
999ac5847dd1604ae74225a8c16f8949
|
|
BLAKE2b-256 |
f065c99b6388619efef388bc0341ea6b9bfbf9f24485e98f76445ac56ad7bb99
|
File details
Details for the file django_json_logger-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_json_logger-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
31638f6271dd9b9f66afd101ed959f987dca798c0c6ebd6edd2cdb94d862accc
|
|
MD5 |
3c22cb1e9c4000d29ac5ca2439e3ff7b
|
|
BLAKE2b-256 |
97610e1361b3c2ef1f91f46738932a1b570ae27d5a29ef135ba04efd3f7fca35
|