折腾:
期间,对于Flask来说,有了自己定义的console和file的log后,却看到PyCharm的debug的console中,还有一个额外的输出的log:
而此处前面已经去掉了flask的debug模式了:
<code>if __name__ == "__main__": # app.debug = True app.run() </code>
为何此处的
[2018-04-18 16:56:59,306] ERROR in testRestApi: error: app=<Flask ‘testRestApi’>
还存在?
想要去删除掉这个root的log
参考:
http://flask.pocoo.org/docs/dev/logging/#removing-the-default-handler
去尝试删除default的log
结果:
<code>from flask.logging import default_handler </code>
就出错:
<code>Connected to pydev debugger (build 173.4127.16) Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1668, in <module> main() File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1662, in main globals = debugger.run(setup['file'], None, None, is_module) File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1072, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo/testRestApi.py", line 4, in <module> from flask.logging import default_handler ImportError: cannot import name 'default_handler' Process finished with exit code 1 </code>
flask logging ImportError cannot import name default_handler
flask logging ImportError default_handler
flask logging default_handler
eduid-common/logging.py at master · SUNET/eduid-common
<code>try: from flask.logging import default_handler # Flask 0.13 except ImportError: default_handler = None </code>
而此处安装的Flask的版本是:
<code>Flask [required: >=0.8, installed: 0.12.2] </code>
所以,找不到default_handler。
才注意到:
Logging — Flask Documentation (0.13-dev)
顶部的:
Warning: This is the documentation for the development version of Flask
看来应该就是:
而从:
Versions
Development (unstable)
Flask 0.12.x (stable)
Flask 0.11.x
Flask 0.10.x
可以看出,此处就是:
我安装的0.12.2是最新的stable版本,而0.13是dev版本,而此文档是dev版本的0.13的。
所以我此处0.12.2中找不到:default_handler
那不管了,接着继续尝试:
删除默认的log
不希望前面的那段log输出。
flask remove default logger
Really disable logger logging in Flask
Ability to disable Flasks internal logger · Issue #1359 · pallets/flask
python – Disable console messages in Flask server – Stack Overflow
Global logging with flask – y.tsutsumi.io
好像可以弄个:全局的log,记录所有的 系统的和app的log
但是这个做法好像看不太懂。。。
<code>app.logger.disabled = True </code>
的确可以把所有log都禁止掉了,都不输出了:
<code>rootLog = logging.getLogger('werkzeug') rootLog.disabled = True </code>
不行,还是有默认log输出。
算了,因为参考:
Ability to disable Flasks internal logger · Issue #1359 · pallets/flask
不去去掉了。
万一需要去掉,后续再去参考:
eduid-common/logging.py at master · SUNET/eduid-common
去试试是否可行。
【总结】
好像是默认的werkzeug的log,后续request请求会用到的,会输出log的
所以此处,还是保留,werkzeug这个log(好像这个是叫做root 或default的log)
转载请注明:在路上 » 【不去解决】Flask中去掉默认的logger的log输出