logging flask errors with mod_wsgi

logging, mod-wsgi, python

Solution

The specific error you created, which was a syntax error, would have caused failure of the WSGI script file to even load in mod_wsgi. The error for this would have ended up in the Apache error log file, not the log file you are setup using the logging module. Have you looked in the Apache error log file?

For an exception raised during request execution, Flask would by default turn it into a 500 error page and otherwise supress the display of the details. You need to set up Flask to mail or log such runtime exceptions in other ways per:

http://flask.pocoo.org/docs/errorhandling/

If you want a runtime exception to be displayed in the 500 page returned to the browser for development purposes, you need to enable Flask debug mode. This is done by setting app.debug to be True:

http://flask.pocoo.org/docs/config/?highlight=app%20debug

You should not have debug mode enabled on a user facing production system.

Problem

I've been trying to get this working since a long time but I'm really at my wits end now. I've tried to do everything that I could find on SO and flask documentation and still I cant a simple error log working so that I can debug my applcation. Below is the pasted code - ``` # main.py from flask import Flask import logging app = Flask(__name__) file_handler = logging.FileHandler(filename='/tmp/election_error.log') file_handler.setLevel(logging.WARNING) app.logger.addHandler(file_handler) @app.route('/') def hello(): return "hello #missing quotes to generate error if __name__ == "__main__": app.run() #wsgi file import sys import logging sys.path.insert(0, "/var/www/voting_app") logging.basicConfig(stream=sys.stderr) from main import app as application # apache2 conf file WSGIDaemonProcess voting_app threads=5 WSGIScriptAlias /election /var/www/voting_app/voting_app.wsgi LogLevel info <Directory /var/www/voting_app> WSGIProcessGroup voting_app WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> ``` Please tell me where I'm going wrong. Thank you so much.

Original source