如何确定要使用的日志级别? [英] How to determine what log level to use?

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

问题描述

日志级别WARN,ERROR和FATAL非常清楚.但是什么时候是DEBUG,什么时候是INFO?

The log levels WARN, ERROR and FATAL are pretty clear. But when is something DEBUG, and when INFO?

我在INFO级别上看到了一些烦人的项目,但是我也看到过分偏爱DEBUG级别的代码.在这两种情况下,有用的信息都被隐藏在噪音中.

I've seen some projects that are annoyingly verbose on the INFO level, but I've also seen code that favors the DEBUG level too much. In both cases, useful information is hidden in the noise.

确定日志级别的标准是什么?

What are the criteria for determining log levels?

推荐答案

我认为没有任何严格的规则;使用log4j类型的级别,我的经验法则"类似于:

I don't think there are any hard-and-fast rules; using the log4j-type levels, my 'rules of thumb' are something like:

  • 致命:该应用程序(或至少是一个线程)即将死亡.这是解释为什么为什么的信息所在的地方.
  • 错误:应用程序不应该执行的操作.这不是用户错误(无效搜索查询");是断言失败,网络问题等,可能是中止当前操作的原因
  • WARN :有关但未导致操作中止的事情;数据库池中的连接数变低,操作中出现异常但异常的超时等.我经常认为"WARN"在总体上很有用;例如grep,分组并计算它们,以了解影响系统运行状况的情况
  • 信息:常规日志记录是应用程序正常运行的一部分;诊断性内容,因此您可以返回并说此广泛操作多久发生一次?"或用户数据如何进入此状态?"
  • 调试:默认情况下处于关闭状态,可以将其打开以调试特定的意外问题.您可以在此处记录有关关键方法参数的详细信息,或用于在代码的特定问题"区域中查找可能存在的问题的其他信息.
  • TRACE :严重的是,WTF在这里发生?!?!我需要记录我执行的每条语句,然后才能发现这个@#$ @ ing内存损坏错误".
  • FATAL: the app (or at the very least a thread) is about to die horribly. This is where the info explaining why that's happening goes.
  • ERROR: something that the app's doing that it shouldn't. This isn't a user error ('invalid search query'); it's an assertion failure, network problem, etc etc., probably one that is going to abort the current operation
  • WARN: something that's concerning but not causing the operation to abort; # of connections in the DB pool getting low, an unusual-but-expected timeout in an operation, etc. I often think of 'WARN' as something that's useful in aggregate; e.g. grep, group, and count them to get a picture of what's affecting the system health
  • INFO: Normal logging that's part of the normal operation of the app; diagnostic stuff so you can go back and say 'how often did this broad-level operation happen?', or 'how did the user's data get into this state?'
  • DEBUG: Off by default, able to be turned on for debugging specific unexpected problems. This is where you might log detailed information about key method parameters or other information that is useful for finding likely problems in specific 'problematic' areas of the code.
  • TRACE: "Seriously, WTF is going on here?!?! I need to log every single statement I execute to find this @#$@ing memory corruption bug before I go insane"

不是一成不变的,而是对我的想法的粗略了解.

Not set in stone, but a rough idea of how I think of it.

这篇关于如何确定要使用的日志级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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