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 ?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With