Skip to content Skip to sidebar Skip to footer

Django Development Logging Httpresponses To Dev Server

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': {

Solution 1:

Logging functionality can be turned off and on by varying the configuration you provide to logging. You might think of the logging statements as "littering" your code, but once the server's running in production, you have (in general) very few ways of knowing what's going on inside, other than logging.

If necessary, you can send a running server a POST with JSON data containing a new configuration, which then gets put into effect by the view handling the POST request. But it's advisable to leave the logging statements in place, as they are quite cheap when logging levels are such that nothing is actually output (as you might expect, the actual I/O of writing to console/file/socket etc. takes most of the time, but if levels are set high enough, little or nothing is actually output).

When everything runs fine in development and test but unaccountably fails in production, logging can sometimes be the only diagnostic tool available.

I think the use of RequireDebugFalse is quite reasonable for the scenario you describe, but you can also write your own filter which fits in more closely with your specific needs (writing Filters is quite easy to do).

Post a Comment for "Django Development Logging Httpresponses To Dev Server"