Reputation: 2185
I am working on flask application and i have used mod_wsgi and Apache to host the flask app. I have setup the logging in app it, but i observe that there are same logs are getting written in apache/logs/error.log like
[wsgi:error] ... BACK TO THE BROWSER
[wsgi:error] ... Selected records from table
[wsgi:error] ... mod_wsgi (pid=1654): Exception occurred processing WSGI script '/tmp/mod_wsgi-localhost:8000:0/htdocs/'.
[wsgi:error] ... ID 1123 Inserted in table
Due to this error.log is getting polluted with wsgi:error and apache errors its getting difficult to analyse the log file.
Is their any way to stop getting written wsgi.errors in error.log files or may we way to redirect these specific logs to seperate log files ?
Upvotes: 1
Views: 12664
Reputation: 23
First, you should add ErrorLog within the VirtualHost, Then you should use flask.logging.default_handler
to log your message.
And be careful that if your request application does not exist in your threadLocal environment, flask will use std.strerr to log the message, and this will due to the message be cached by the main log instead of VirtualHost log.
Upvotes: 0
Reputation: 14361
I typically add an ErrorLog to my VirtualHost. Here's an example Apache VirtualHost I use:
<VirtualHost *:443>
ServerName yourservername.com
ErrorLog /home/yourusername/apache_errors.log
WSGIDaemonProcess yourproject-https python-home=/home/yourusername/.virtualenvs/yourproject
WSGIScriptAlias /yourproject /var/www/html/yourproject/yourproject/wsgi.py process-group=yourproject-https application-group=yourproject-https
WSGIProcessGroup yourproject-https
Alias /yourproject/static/ /var/www/html/yourproject/static/
SSLENGINE on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLProtocol all -SSLv2
</VirtualHost>
Would that do the trick? You can choose a path other than your home directory, of course.
Upvotes: 1