在一般情况下,你可以找到任何库logging
实例,并调整日志记录级别
您可以通过werkzeug._internal
from werkzeug._internal import _logger
然后我调整根记录到logging.CRITICAL
访问logging
实用程序(其中是50
)
_logger.setLevel(50)
这意味着Werkzeug
将只打印CRITICAL
(或更高版本)输出
,然后可以调整根据该_logger
水平得到了您的需求
直接的例子
这适用于你的例子由Werkzeug
github上搜索的import logging
命令页。这是我在werkzeug._internal
找到,那么我们可以做
In [2]: from werkzeug.wrappers import Request, Response
...:
...: @Request.application
...: def application(request):
...: return Response('Hello World!')
...:
In [3]: from werkzeug.serving import run_simple
In [4]: run_simple('localhost', 4000, application)
* Running on http://localhost:4000/ (Press CTRL+C to quit)
In [5]: from werkzeug import _internal
In [6]: _internal._log('info', 'Setting logger level to Critical!') # see below why this is required
Out[6]: 'Setting logger level to Critical!'
In [7]: _internal._logger.setLevel(50)
In [7]: run_simple('localhost', 4000, application)
在_logger is None
再发生这种情况,因为没有Werkzeug
记录例如被称为情况。为了更清楚
In [1]: from werkzeug import _internal
In [2]: type(_internal._logger)
Out[2]: NoneType
In [3]: _internal._log('info', 'removing logger!')
removing logger!
In [4]: type(_internal._logger)
Out[4]: logging.Logger
见
_internal
line 75这瓶?你如何启动应用程序?也许你是在调试模式下启动它的。也看看[在此](https://stackoverflow.com/questions/23552231/cant-enable-debug-mode-in-flask)。它可能有帮助。 – rocksteady另外,请考虑将代码标记为代码,即使它是日志消息。在我看来,这有助于阅读你的问题。 – rocksteady
编辑到OP is pending @rocksteady –