Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does flask logs only when app.debug = True?

Tags:

python

flask

in main :

handler = RotatingFileHandler('/tmp/mylog')
handler.setLevel(logging.DEBUG)
app.logger.addHandler(handler)
my_glob.logger = app.logger
app.debug = True
app.run(host='0.0.0.0', port=80)

in a 'url' :

import my_glob
...
handling get request here:
  logger = my_glob.logger
  logger.info('this wont show unless app.debug=True is specified')
  logger.error('this always shows up')

if I do this, it works. If I remove app.debug = True, it doesn't work. But flask documentation says that app.debug is on local environments/debugging, not on production. So what should I use to enable logging on info/debug levels ?

like image 818
Thomas Avatar asked Dec 06 '13 10:12

Thomas


1 Answers

This is because flask considers ERROR as the default logging level if you do not set up log level, see: https://github.com/mitsuhiko/flask/blob/master/flask/logging.py#L28.

The solution is to add app.logger.setLevel(logging.DEBUG) before usage.

like image 76
tbicr Avatar answered Sep 22 '22 18:09

tbicr