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'})
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
Close
Hashes for django_json_logger-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a1653f337a5894b7a4267c7ea5e1daf840fb19df6928833a75fd73fbd826d97 |
|
MD5 | db80a28fbfdc22c964daf60ebb20cf91 |
|
BLAKE2b-256 | 9de0ac90aeb45e2fac55969dce08f2e990332c7a6e09b136b84151380cd595c9 |