我应该将消息记录到 stderr 还是 stdout? [英] Should I log messages to stderr or stdout?
问题描述
我正在编写一个程序,我想为其编写自定义日志记录工具(例如诊断、通知、警告、错误).
I have a program I'm writing that I want to write a custom logging facility for (e.g. diagnostic, notice, warning, error).
我应该使用 stdout
还是 stderr
流来执行此操作?它是一种解释器,用户可以要求它打印输出.
Should I be using the stdout
or the stderr
stream to do this? It is an interpreter of sorts and the user can ask it to print output.
请停止向我推荐日志框架:(
Please stop recommending me logging frameworks :(
推荐答案
常规输出(运行程序的实际结果)应该继续stdout
,像你提到的(例如诊断,通知,stderr
上的警告、错误).
Regular output (the actual result of running the program) should go on stdout
, things like you mentioned (e.g. diagnostic, notice, warning, error) on stderr
.
如果没有常规输出",我会说你选择哪一个并不重要.您可能会争辩说日志记录是唯一的输出,因此应该转到 stdout
.或者你可以争辩说它仍然是特殊信息",应该转到 stderr
.
If there is no "regular output", I would say that it doesn't really matter which one you choose. You could argue that the logging is the only output, so that should go to stdout
. Or you could argue that it is still "exceptional information" which should go to stderr
.
这篇关于我应该将消息记录到 stderr 还是 stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!