python - 为什么 Python 日志记录默认写入 stderr?

标签 python logging default stderr

相关 Does Python logging write to stdout or stderr by default?但我想知道为什么它默认为 stderr相反 什么 是默认值。

对我来说,为什么 stderr 并不是很明显是默认值。我注意到运行 python script.py | tee out.log 时出了点问题并以空的日志文件结束。现在我知道它可以通过 python script.py 2>&1 | tee out.log 解决或使用 stream范围:

logging.basicConfig(stream=sys.stdout)

在那次事件之后,我认为更改默认值是合理的 streamstdout在每个脚本中,以避免再次感到惊讶。这是一个好习惯吗?我会错过什么吗?

最佳答案

您可能不想将默认值更改为 stdout。
原因是 stderr 是所有消息的输出,这些消息只是一些内部和/或调试程序信息,如日志和错误,而不是实际输出,程序的结果。

关于python - 为什么 Python 日志记录默认写入 stderr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58971197/

相关文章:

python - Django 在管理中的内联之间切换

c# - 为 ASP.NET 核心创建基础 Controller 来进行日志记录,但我的构造函数签名有问题吗?

date - Symfony2/Doctrine "app/console doctrine:schema:update --force"带来一个 ContextErrorException

c - 取决于调试级别的函数多态性

java - 配置Log4J每天写入新文件新日志文件

sorting - SOLR - 没有任何默认排序的搜索结果

architecture - 多层架构中的默认函数值

python - 生成器表达式中的多个产量? Python

python - 使用 Python 自动将 PNG 转换为 JPG

python - query.filter 和 gql