简体   繁体   English

Python 禁止控制台日志中的警告消息

[英]Python suppress warnings messages in console logs

I have a python program that when I run works as expected but there is this annoying statement that spams my console logs.我有一个 python 程序,当我运行时,它按预期工作,但是有一条烦人的语句会向我的控制台日志发送垃圾邮件。

W0131 18:09:51.881016 2064 default_variables.cpp:91] Fail to fscanf: Success [0]

I am not sure where is this coming from and I tried looking for solutions to suppress this but couldn't find a relevant solution.我不确定这是从哪里来的,我尝试寻找解决方案来抑制它,但找不到相关的解决方案。

I tried using python warnings package but it is not working in this case.我尝试使用 python 警告 package 但在这种情况下它不起作用。

import warnings
warnings.filterwarnings("ignore")

I also tried these but they didn't work here.我也尝试了这些,但它们在这里不起作用。

export PYTHONWARNINGS="ignore"

and

python -W ignore my_script.py

It looks like someone else also has faced this issue: https://github.com/typesense/typesense/issues/208 but the issue is closed without a proper solution.看起来其他人也遇到了这个问题: https://github.com/typesense/typesense/issues/208但是这个问题没有适当的解决方案就关闭了。

python -W ignore test.py

Use -W ignore flag.使用-W ignore标志。

There is also the option to use a env var:还可以选择使用 env var:

export PYTHONWARNINGS="ignore"

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

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