Search code examples
pythonloggingflaskwsgipythonanywhere

Logging format for Flask on PythonAnywhere


I'm running a Flask web app on PythonAnywhere. The access logs xyz.pythonanywhere.com.access.log have the format:

12.34.167.189 - - [07/Aug/2018:04:33:46 +0000] "GET /foo/bar?id=abc HTTP/1.1" 200 117942 "-" "-" "12.34.167.189" response-time=0.041

I'm trying to get rid of the IPs.

All approaches modifying or overriding the logger didn't work. The following lines successfully effect the logging on my local machine:

import logging
from werkzeug.serving import WSGIRequestHandler
logger = logging.getLogger('werkzeug')
WSGIRequestHandler.log = lambda self, type, msg, *args: getattr(logger, type)(msg % args)

On PythonAnywhere, however, Flask is started differently from /var/www/xyz_pythonanywhere_com_wsgi.py. The logging format didn't change.

So, how can I configure the WSGI logging?


Solution

  • The access log is not run through Python. That's directly from nginx. There is no way to change it.