views:

54

answers:

1
+1  Q: 

Python: __debug__

I'd like a global variable to determine if I'm in debug mode or not. Is that what __debug__ is for? How do I set/read it on Google App Engine?

If I use logging.debug(), will that automatically be turned off if I don't run the app with debug=True?

application = webapp.WSGIApplication(# ...
                                        debug=True)
+1  A: 

__debug__ is built-in constant defined by Python. The docs say this: "This constant is true if Python was not started with an -O option. Assignments to debug are illegal and raise a SyntaxError. See also the assert statement."

The debug=True you pass to webapp.WSGIApplication is completely separate.

Neither of these will affect logging.debug() either. You can use logging.setLevel() to control how logging.debug() is handled.

David Underhill
logging.setlevel isn't advisable for App Engine - the logger in production logs everything into separate logs, separated by level anyway.
Nick Johnson