log4j 日志记录层次结构顺序
log4j 日志记录的层次结构是什么?
DEBUG
INFO
WARN
ERROR
FATAL
哪一个提供最高的日志记录,这有助于解决问题? 任何人都可以提供从最高到最低进行日志记录的顺序或层次结构吗? 谢谢!
What is the hierarchy of log4j logging?
DEBUG
INFO
WARN
ERROR
FATAL
Which one provides the highest logging which would be helpful to troubleshoot issues?
Can any one provide the order or hierarchy in which logging take place from highest to lowest?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
此表可能对您有帮助:
在第一列中,您将看到日志在每个级别中的工作方式。即对于 WARN,(FATAL、ERROR 和 WARN)将可见。对于关闭,没有任何内容可见。
This table might be helpful for you:
Going down the first column, you will see how the log works in each level. i.e for WARN, (FATAL, ERROR and WARN) will be visible. For OFF, nothing will be visible.
使用force,阅读源码(摘自编译的
Priority
和Level
类,TRACE level是1.2.12版本引入的):或者
Level
类的 log4j API,其中使它相当 清除。当库决定是否打印某个语句时,它会计算负责的 Logger 对象的有效级别(基于配置)并将其与 LogEvent 的有效级别进行比较级别(取决于代码中使用的方法 - trace/debug/.../fatal)。如果
LogEvent
的级别大于或等于Logger
的级别,则将LogEvent
发送到附加程序 – “打印” 。从本质上讲,这一切都归结为整数比较,这就是这些常量发挥作用的地方。Use the force, read the source (excerpt from the
Priority
andLevel
class compiled, TRACE level was introduced in version 1.2.12):or the log4j API for the
Level
class, which makes it quite clear.When the library decides whether to print a certain statement or not, it computes the effective level of the responsible
Logger
object (based on configuration) and compares it with theLogEvent
's level (depends on which method was used in the code – trace/debug/.../fatal). IfLogEvent
's level is greater or equal to theLogger
's level, theLogEvent
is sent to appender(s) – "printed". At the core, it all boils down to an integer comparison and this is where these constants come to action.log4j 日志记录级别的层次结构按从高到低的顺序排列如下:
TRACE 日志级别提供最高的日志记录,这有助于解决问题。 DEBUG 日志级别对于解决问题也非常有用。
您还可以参考此链接以获取有关日志级别的更多信息:
https://logging.apache.org/log4j/2.0/manual/architecture.html
Hierarchy of log4j logging levels are as follows in Highest to Lowest order :
TRACE log level provides highest logging which would be helpful to troubleshoot issues. DEBUG log level is also very useful to trouble shoot the issues.
You can also refer this link for more information about log levels :
https://logging.apache.org/log4j/2.0/manual/architecture.html
[摘自http://javarevisited.blogspot.com /2011/05/top-10-tips-on-logging-in-java.html]
DEBUG 是最低的限制 java 日志记录级别,我们应该编写调试应用程序所需的所有内容,这java 日志记录模式只能在开发和测试环境中使用,不得在生产环境中使用。
INFO 比 DEBUG java 日志记录级别受到更多限制,我们应该在 java 中的 INFO 级别日志记录中记录信息性目的的消息,例如服务器已启动、传入消息、传出消息等。
WARN 比 INFO java 日志记录级别受到更多限制,用于记录警告类型的消息,例如客户端和服务器之间的连接丢失。数据库连接丢失,Socket 达到极限。这些消息和 java 日志记录级别几乎很重要,因为您可以在 java 中对这些日志消息设置警报,并让您的支持团队监控 java 应用程序的运行状况并对这些警告消息做出反应。总结 WARN 级别用于记录 Java 日志记录的警告消息。
ERROR 是比 WARN 更受限制的 java 日志记录级别,用于记录错误和异常,您还可以在此 java 日志记录级别上设置警报,并提醒监控团队对此消息做出反应。对于 Java 中的日志记录,错误很严重,您应该始终打印它。
FATAL java 日志记录级别指定非常严重的错误事件,可能会导致应用程序中止。在此之后,您的应用程序大部分会崩溃并停止。
OFF java 日志记录级别具有最高的级别,旨在关闭 Java 中的日志记录。
[Taken from http://javarevisited.blogspot.com/2011/05/top-10-tips-on-logging-in-java.html]
DEBUG is the lowest restricted java logging level and we should write everything we need to debug an application, this java logging mode should only be used on Development and Testing environment and must not be used in production environment.
INFO is more restricted than DEBUG java logging level and we should log messages which are informative purpose like Server has been started, Incoming messages, outgoing messages etc in INFO level logging in java.
WARN is more restricted than INFO java logging level and used to log warning sort of messages e.g. Connection lost between client and server. Database connection lost, Socket reaching to its limit. These messages and java logging level are almost important because you can setup alert on these logging messages in java and let your support team monitor health of your java application and react on this warning messages. In Summary WARN level is used to log warning message for logging in Java.
ERROR is the more restricted java logging level than WARN and used to log Errors and Exception, you can also setup alert on this java logging level and alert monitoring team to react on this messages. ERROR is serious for logging in Java and you should always print it.
FATAL java logging level designates very severe error events that will presumably lead the application to abort. After this mostly your application crashes and stopped.
OFF java logging level has the highest possible rank and is intended to turn off logging in Java.
我发现“日志记录级别”这个术语有点令人困惑,所以我更喜欢这样思考:
按照惯例,log4j 定义了一些标准日志级别。在 v2.x 中,这些是(按严重性降序排列):
关闭
、致命
、错误
、警告
、信息
、调试< /代码>,<代码>跟踪,<代码>全部。请注意,OFF 和 ALL 仅用作记录器阈值,而不是事件严重性级别。您还可以添加自己的自定义级别,并为其指定数值。
记录器将忽略严重程度低于其阈值的任何事件:
OFF
表示不记录日志。FATAL
表示仅记录 FATAL 事件(或更糟)。ERROR
意味着仅记录ERROR、FATAL(或更糟)。ALL
的阈值意味着所有事件都被记录(最详细的选项)作为图表(基于显示的表格在 log4j v2.x 文档中)它看起来像这样:
I find the term "logging level" to be a bit confusing, so I prefer to think of it like this:
By convention, log4j defines some Standard Log Levels. In v2.x these are (in order of decending severity):
OFF
,FATAL
,ERROR
,WARN
,INFO
,DEBUG
,TRACE
,ALL
. Note that OFF and ALL are only intended as Logger threshold values, not Event severity levels). You can also add your own custom levels, and assign them a numerical value.A Logger will ignore any events less severe than its threshold:
OFF
means no logging.FATAL
means only FATAL events (or worse) are logged.ERROR
means only ERROR, FATAL (or worse) are logged.WARN
means only WARN, ERROR, FATAL (or worse) are logged.ALL
means all events are logged (the most verbose option)As a diagram (based on the table shown in the log4j v2.x docs) it looks like this:
层次结构顺序
Hierarchy order
需要明确的是,log4j 中没有像“层次结构”这样的定义术语。
是的,有不同的级别。为了进行故障排除,您必须选择所需日志的级别。
To make it clear, there is no defined term like 'hierarchy' in log4j.
Yes there are different levels. For troubleshooting you have to select which level you want the logs.
添加 .NET 日志级别以供参考
https: //learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0
Adding .NET log levels for reference
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0
下表说明了级别过滤的工作原理。
在表中,垂直标题显示您要在应用程序设置中配置的 LogEvent 的级别,而水平标题显示与相应配置关联的级别可见性。
交集标识 LogEvent 是否允许显示日志以供进一步处理(是)或丢弃(否)。
The table below illustrates how Level filtering works.
In the table, the vertical header shows the level of the LogEvent you want to configure in your app settings, while the horizontal header shows the Level visibility in associated with the appropriate config.
The intersection identifies whether the LogEvent would be allowed to display logs for further processing (Yes) or discarded (No).
跟踪 -->调试-->信息 --> 警告 -->错误 --> FATAL
如果日志级别设置为 WARN。它将记录所有警告及其以下所有级别。(错误和致命)。
如果为 TRACE 设置日志级别。它将记录所有 TRACE 及其下面的所有级别。(DEBUG、INFO、WARN、ERROR、FATAL)。
TRACE --> DEBUG--> INFO -->WARN --> ERROR --> FATAL
If Log level is set for WARN. it will log all the WARN and all levels below it.(ERROR and FATAL).
If Log level is set for TRACE. it will log all the TRACE and all levels below it.(DEBUG,INFO,WARN,ERROR,FATAL).