Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7631111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:16:11+00:00 2026-05-31T06:16:11+00:00

I am creating an API using Django. Every view responds in JSON. I would

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:16:12+00:00Added an answer on May 31, 2026 at 6:16 am

    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).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating Email client using JavaMail API. Everything is working fine like I
I am currently in the process of creating API documentation using Microsoft Word 2007
I'm creating a small service using api-libraries, such as Twitter. Is it possible to
When creating a child process in C++ using Windows API, one can allow inheritance
I'm creating .net websites against a CMS server using the API of the software
I am creating a map using the new(ish) v3 of the Google Maps API
I'm creating a simple API that creates typed classes based on JSON data that
I decided to try creating a simple C wrapper for the V8 API using
I'm investigating in using Microsoft's WCF WebHttp Services for creating a RESTful API. In
I am creating an API using PHP and MongoDB. In this system I got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.