为什么只有在 app.debug = True 时 Flask 才记录日志?

5

在主函数中:

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)

在一个“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')

如果我这样做,它就能运行。如果我移除 app.debug = True,它就不能运行。但 Flask 文档说 app.debug 只在本地环境/调试时使用,而不是在生产环境中使用。那么我该使用什么来启用信息/调试级别的日志记录呢?

1个回答

6

1
但是如果INFO是默认值,为什么logger.info(...)没有显示出来呢? - Thomas
刚遇到了同样的问题,现在完美解决了。@Thomas 你能接受这个答案吗? - Cedric Meury

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接