Reputation: 2425
If I have a python app running in Google App Engine, how can I dynamically change the app's logging level during runtime? The app's logging level is currently done via a logging config file.
One brute force way is to update the logging config file locally, and run 'appcfg.py -R update path_to_product'. But this will update all modified files.
Is there a better way to do this?
I looked at dictConfig and fileConfig. But using these methods would not update the logging configuration of running processes (especially those running on different app engine instances).
Upvotes: 2
Views: 4140
Reputation: 1863
You can create a handler method and call it to dynamically set the log level at runtime.
eg:
def logLevel(self, request):
# ?value= NOTSET, DEBUG, INFO, WARN, ERROR, FATAL, CRITICAL
value = request.value.upper() if request.value else None
logging.info("Setting log level to: {}".format(value))
logging.getLogger().setLevel(value)
logging.debug("Test debug")
logging.info("Test info")
logging.warn("Test warn")
logging.error("Test error")
logging.critical("Test critical")
Specific loggers may also be targeted eg:
logging.getLogger('suds').setLevel(value)
(Note that in the GAE launcher 'debug' logs are not shown by default.)
Upvotes: 2