有人真的使用WARN作为日志记录级别吗? [英] Does anyone really use WARN as a logging level?

查看:76
本文介绍了有人真的使用WARN作为日志记录级别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅仅为警告而不是错误分配一个不同的级别似乎有点过头了.如果一个值是错误的,那么它的错误就可以了.我个人认为这些模糊的决策会使代码难以理解,因为人们不知道是什么构成了可接受的有效输入.如果您不接受废话并引发异常,那么您的代码可能会更好,完全不需要警告.

It seems like abit of overkill to allocate a different level just for a warning as opposed to error. If a value is wrong its wrongm its ok its not. Personally i tink these sort of fuzzy decisions make code difficult to understand because one know is not sure what consititutes acceptable valid input. If you do not accept crap and throw exceptions then hyour code will probably be the better for it, removing the need for warning altogether.

还有许多其他级别可以获取更多日志记录,这些日志可能更值得他们自己使用-诸如"config"之类的东西.但是最终,大多数框架似乎都选择了错误,警告,信息,调试和跟踪以及它们的变体.

There are many other levels that get more logging that are probably more deserving of their own level - stuff like "config". However in the end it seems that most frameworks have settled on error, warning, info, debug and trace with variations thereof.

那么警告如何生存而其他级别却没有?

So how did warning survive and other levels did not ?

推荐答案

对于我使用的软件,我使用以下区别.

For the software I work on, I use the following distinctions.

  • 错误:程序无法执行要求执行的操作.如果程序无法执行请求的操作,则需要输出 error 消息.
  • 警告:程序检测到奇怪的东西,这并不妨碍它执行要求的操作.程序可以,但不是必需的 ,以在出现特殊情况时输出警告消息.
  • error: the program is unable to perform the operation it has been requested to do. The program is required to output an error message if it can not do what it was requested to do.
  • warning: the program has detected something odd, which does not prevent it doing what it has been requested to do. The program may, but is not required, to output a warning message for odd situations.

其他人也这样做.

例如,想象一个配置文件,其中包含程序要检查的位置列表,该列表可能为空,但实际上永远不会为空.

For example, imagine a configuration file that contains a list of locations that the program is to examine, and that list may be empty but is practically never empty.

  • 如果配置文件格式错误,程序将报告一条错误消息,因为配置文件无法确定您想要执行的操作,因此无法执行您想要的操作.
  • 如果配置文件中未列出任何位置,它可能会报告警告,因为尽管在这种情况下它可以正确地检查任何位置(也就是说,没有任何用处),但用户可能会事实错误地配置了系统.
  • The program would report an error message if the configuration file had the incorrect format, because it could not then work out what you want it to do and therefore can not do what you want.
  • It might report a warning if the configuration file listed no locations, because although it can correctly examine no locations in that case (that is, do nothing useful), it is likely that the user in fact incorrectly configured the system.

这篇关于有人真的使用WARN作为日志记录级别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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