Python logger stops logging after uncaught exception Python logger stops logging after uncaught exception flask flask

Python logger stops logging after uncaught exception


In regards to after_request, from the docs:

As of Flask 0.7 this function might not be executed at the end of the request in case an unhandled exception occurred.

And as for your logging issue, it may be that your debug flag is set to true, which would cause the debugger to kick in and possibly stop the logging.

References:
(http://flask.pocoo.org/docs/0.10/api/#flask.Flask.after_request)
(http://flask.pocoo.org/docs/0.10/errorhandling/#working-with-debuggers)


You didn't provide enough information.

Is the application still working after the exception?Which type of exception is raised and what's the cause of it?Are you using threads in you application?How is the logging library used? Does it log on a file? Does it use log rotation?

Supposing you're using threads in you application, the explanation is that the exception causes the Thread to shut down, therefore you won't see any activity from that specific thread. You should notice issues with the application as well.

If the application is still working but becomes silent, my guess is that the logging library is not configured properly. As you reported on Serverfault, the issue seemed to appear after adding fluentd which might not play well with the way your application uses the logging library.