简体   繁体   English

调试模式下的 Flask 应用程序不会显示信息或调试日志消息

[英]Flask app in debug mode won't show info or debug log messages

I'm starting a flask application like this:我正在启动这样的烧瓶应用程序:

from idapi.wsgi import app
app.run(port=8080, debug=True)

Where app is an object of a subclass of flask.Flask .其中appflask.Flask子类的flask.Flask Within the application, I'm only ever calling app.logger.<level> (or self.logger.<level> within the class itself).在应用程序中,我只在类本身中调用app.logger.<level> (或self.logger.<level> )。 I'm never importing the Python logging module itself.我从不导入 Python logging模块本身。

My understanding was that when startring a flask app with debug=True , I should see see messages from app.logger.debug(...) and app.logger.info(...) , but I'm not.我的理解是,当使用debug=True启动烧瓶应用程序时,我应该看到来自app.logger.debug(...)app.logger.info(...) ,但我没有。

I can solve this problem by explicitly configuring the root logger:我可以通过显式配置根记录器来解决这个问题:

import logging
from idapi.wsgi import app

logging.basicConfig(level='DEBUG')

app.run(port=8080, debug=True)

Or I can use app.logger.warning(...) instead.或者我可以使用app.logger.warning(...)代替。 What could be going on here...am I incorrect in my understanding of how logging is configured by Flask when running in debug mode?这里可能会发生什么......我对在调试模式下运行时 Flask 如何配置日志记录的理解不正确吗?

I'm not sure, but in the documentation of Flask I've seen that you need to set variable FLASK_ENV to development if you want to see debug messages:我不确定,但在Flask文档中,我看到如果您想查看调试消息,您需要将变量 FLASK_ENV 设置为 development:

To enable all development features (including debug mode) you can export the FLASK_ENV environment variable and set it to development before running the server:要启用所有开发功能(包括调试模式),您可以在运行服务器之前导出 FLASK_ENV 环境变量并将其设置为 development:

$ export FLASK_ENV=development $ export FLASK_ENV=development

$ flask run $烧瓶运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM