Flask: Question: can flask create 'access.log', and 'error.log'

Created on 12 Apr 2016  路  1Comment  路  Source: pallets/flask

I am hoping to create two types of logs:

  • access.log: lists all requests made on the flask application
  • error.log: lists all warnings, and errors made within the flask application

Currently, I have defined app.py, which contains logic recycled from a gist comment:

import logging
from logging.handlers import RotatingFileHandler
from interface import app
app.run(host='0.0.0.0')

LOG_FILENAME = '/vagrant/log/access.log'

formatter = logging.Formatter(
    "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler = RotatingFileHandler(LOG_FILENAME, maxBytes=10000000, backupCount=5)
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)
app.logger.addHandler(handler)

log = logging.getLogger('werkzeug')
log.setLevel(logging.DEBUG)
log.addHandler(handler)

When I adjust my application, by making an unnecessary typo in the logic; or conversely, if I complete a successful post request on my application, nothing gets logged into /vagrant/log/access.log. However, the /vagrant/log/access.log file is created, and empty. Is the above logic equivalent to the error.log that I had intended? If so, how can I correct this, while also creating a functional /vagrant/log/access.log?

>All comments

Please take this to StackOverflow.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stillesjo picture stillesjo  路  4Comments

rkomorn picture rkomorn  路  3Comments

ghost picture ghost  路  3Comments

xliiv picture xliiv  路  3Comments

westonplatter picture westonplatter  路  3Comments