I am creating an API using Django. Every view responds in JSON. I would like to log each HttpResponse JSON to the dev servers output.
So far I have added a handler:
'console': {
'level':'DEBUG',
'class':'logging.StreamHandler',
}
and then added a logger:
'to_console': {
'handlers': ['console'],
'level': 'DEBUG',
}
In my view I get the logger logger = logging.getLogger('to_console')
and for each json response logger.debug(json_str)
For the first view this was fine. But I'm wondering is it possible to turn debug off when I deploy the app to production. It looks like https://docs.djangoproject.com/en/dev/topics/logging/#django.utils.log.RequireDebugFalse could work. But then that leads my code littered with these logging statements. I have never needed to log somethign like this so I am wondering what the most maintainable way to handle it is.
What is the correct way to handle development logging so that it can be "turned-off" when code is on production? Or is there some sort of built in functionality or app that I am missing that automatically logs all HttpResponse's to the dev server?