我应该将消息记录到stderr还是stdout? [英] Should I log messages to stderr or stdout?

查看:74
本文介绍了我应该将消息记录到stderr还是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆