Specifically, you need to know how to define a custom formatter in a dictionary config for a logger. All the examples are in UML or use the old-style method of instantiating a formatter and assigning it to a handler.
This makes use of the python-json-logger, available here:
https://github.com/madzak/python-json-logger
So, here is a working example. Simply do this in your own code and you'll be all set. Note that in Django you don't have to deal with the dictConfig at all -- just put the right things in your dictionary and Django will do the rest.
#!/usr/bin/env python
import logging
from logging.config import dictConfig
import jsonlogger
log_config = {
'version': 1,
'formatters': {
'json': {
'()': 'jsonlogger.JsonFormatter',
'fmt': '%(levelname)s %(asctime)s %(message)s',
},
},
'handlers': {
'stream': {
'level': 'DEBUG',
'formatter': 'json',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'my_logger': {
'handlers': ['stream'],
'level': 'DEBUG',
'propagate': True,
},
}
}
dictConfig(log_config)
logger = logging.getLogger('my_logger')
logger.debug('foo')