如何确定使用什么日志级别?
日志级别 WARN、ERROR 和 FATAL 非常清楚。 但是什么时候是 DEBUG,什么时候是 INFO?
我见过一些项目在 INFO 级别上冗长得令人恼火,但我也见过过于偏向于 DEBUG 级别的代码。 在这两种情况下,有用的信息都隐藏在噪音中。
确定日志级别的标准是什么?
The log levels WARN, ERROR and FATAL are pretty clear. But when is something DEBUG, and when INFO?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我认为没有什么硬性规定; 使用 log4j 类型的级别,我的“经验法则”类似于:
不是一成不变的,但大致了解我的想法。
I don't think there are any hard-and-fast rules; using the log4j-type levels, my 'rules of thumb' are something like:
Not set in stone, but a rough idea of how I think of it.
非正式地,我使用这种层次结构,
我通常会在记录信息的情况下发布,但前提是我知道日志文件实际上已被审查(并且大小不是问题),否则是警告。
Informally I use this sort of hierarchy,
I'll generally release with INFO being logged, but only if I know that log files are actually reviewed (and size isn't an issue), otherwise it's WARN.
考虑谁需要使用每个级别。
在我的代码中,我为开发人员输出保留DEBUG,例如仅对开发人员有帮助的输出。
VERBOSE 用于普通用户需要大量信息时。
INFO 我通常用来显示重大事件(例如发送网页、检查重要的内容)。
FAIL 和 WARN 是非常不言自明的。
Think about who needs to use each level.
In my code I keep DEBUG reserved for a developer output, e.g. output that would only help a developer.
VERBOSE is used for a normal user when alot of info is needed.
INFO I use to normally show major events (e.g. sending a webpage, checking something important).
And FAIL and WARN are pretty self explanatory.
我团队的惯例是,如果消息中计算出某些内容,则使用
debug
,而info
用于纯文本。 因此,实际上info
将向您显示正在发生的事情,而debug
将显示正在发生的事情的值。The convention in my team is to use
debug
if something is calculated in the message, whereasinfo
is used for plain text. So in effectinfo
will show you what's happening anddebug
will show the values of the things that are happening.我倾向于将 INFO 定位于用户,向他们提供甚至不是警告的消息。 DEBUG 往往供开发人员使用,我在其中输出消息以帮助跟踪代码流(也包含变量值)。
我还喜欢另一个级别的 DEBUG(DEBUG2?),它提供了调试信息的绝对存储桶负载,例如所有缓冲区的十六进制转储等。
I tend to target INFO towards the user to give them messages that aren't even warnings. DEBUG tends to be for developer use where I output messages to help trace the flow through the code (with values of variables as well).
I also like another level of DEBUG (DEBUG2?) which gives absolute bucketloads of debug information such as hex dumps of all buffers and so on.
不需要 DEBUG2 级别。 这就是“TRACE”的用途。 TRACE 旨在成为绝对最低级别的日志记录,输出您可能希望看到的每条可能的信息。
为了避免信息泛滥,通常不建议您在整个项目中启用跟踪级别日志记录。 相反,请使用“DEBUG”来查找有关错误及其发生位置(因此得名)的一般信息,然后如果您仍然无法弄清楚,则仅针对该组件启用 TRACE。
There's no need for a DEBUG2 level. That's what 'TRACE' is for. TRACE is intended to be the absolute lowest level of logging outputting every possible piece of information you might want to see.
To avoid a deluge of information, it is generally not recommended that you enable trace-level logging across an entire project. Instead use 'DEBUG' to find out general information about the bug and where it occurs (hence the name), and then enable TRACE only for that component if you still can't figure it out.