log4j 日志记录层次结构顺序

发布于 2024-12-09 15:57:00 字数 146 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

梦途 2024-12-16 15:57:00

此表可能对您有帮助:

日志级别

在第一列中,您将看到日志在每个级别中的工作方式。即对于 WARN,(FATAL、ERROR 和 WARN)将可见。对于关闭,没有任何内容可见。

This table might be helpful for you:

Log Level

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.

甜宝宝 2024-12-16 15:57:00

使用force,阅读源码(摘自编译的PriorityLevel类,TRACE level是1.2.12版本引入的):

public final static int OFF_INT = Integer.MAX_VALUE;
public final static int FATAL_INT = 50000;
public final static int ERROR_INT = 40000;
public final static int WARN_INT  = 30000;
public final static int INFO_INT  = 20000;
public final static int DEBUG_INT = 10000;
public static final int TRACE_INT = 5000; 
public final static int ALL_INT = Integer.MIN_VALUE; 

或者Level 类的 log4j API,其中使它相当 清除。

当库决定是否打印某个语句时,它会计算负责的 Logger 对象的有效级别(基于配置)并将其与 LogEvent 的有效级别进行比较级别(取决于代码中使用的方法 - trace/debug/.../fatal)。如果 LogEvent 的级别大于或等于 Logger 的级别,则将 LogEvent 发送到附加程序 – “打印” 。从本质上讲,这一切都归结为整数比较,这就是这些常量发挥作用的地方。

Use the force, read the source (excerpt from the Priority and Level class compiled, TRACE level was introduced in version 1.2.12):

public final static int OFF_INT = Integer.MAX_VALUE;
public final static int FATAL_INT = 50000;
public final static int ERROR_INT = 40000;
public final static int WARN_INT  = 30000;
public final static int INFO_INT  = 20000;
public final static int DEBUG_INT = 10000;
public static final int TRACE_INT = 5000; 
public final static int ALL_INT = Integer.MIN_VALUE; 

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 the LogEvent's level (depends on which method was used in the code – trace/debug/.../fatal). If LogEvent's level is greater or equal to the Logger's level, the LogEvent 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.

雨后咖啡店 2024-12-16 15:57:00
OFF
FATAL
ERROR
WARN
INFO
DEBUG
TRACE
ALL
OFF
FATAL
ERROR
WARN
INFO
DEBUG
TRACE
ALL
十秒萌定你 2024-12-16 15:57:00

log4j 日志记录级别的层次结构按从高到低的顺序排列如下:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF

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
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF

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

第几種人 2024-12-16 15:57:00

[摘自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.

云淡月浅 2024-12-16 15:57:00

我发现“日志记录级别”这个术语有点令人困惑,所以我更喜欢这样思考:

  • 事件有一个SEVERITY(一个级别)。在 log4j 中,它被建模为整数。
  • 记录器有一个THRESHOLD(又名 LoggerConfig 级别,用于过滤事件)

按照惯例,log4j 定义了一些标准日志级别。在 v2.x 中,这些是(按严重性降序排列):
关闭致命错误警告信息调试< /代码>,<代码>跟踪,<代码>全部。请注意,OFFALL 仅用作记录器阈值,而不是事件严重性级别。您还可以添加自己的自定义级别,并为其指定数值。

记录器将忽略严重程度低于其阈值的任何事件:

  • 阈值OFF 表示不记录日志。
  • 阈值 FATAL 表示仅记录 FATAL 事件(或更糟)。
  • 阈值ERROR意味着仅记录ERROR、FATAL(或更糟)。
  • 阈值 WARN 意味着仅记录 WARN、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:

  • Events have a SEVERITY (a level). In log4j this is modelled as an integer.
  • Loggers have a THRESHOLD (aka a LoggerConfig level, used to filter Events)

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:

  • A threshold of OFF means no logging.
  • A threshold of FATAL means only FATAL events (or worse) are logged.
  • A threshold of ERROR means only ERROR, FATAL (or worse) are logged.
  • A threshold of WARN means only WARN, ERROR, FATAL (or worse) are logged.
  • etc...
  • A threshold of 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:

logging levels cheat sheet

假装爱人 2024-12-16 15:57:00

层次结构顺序

  1. ALL
  2. TRACE
  3. DEBUG
  4. INFO
  5. WARN
  6. ERROR
  7. FATAL
  8. OFF

Hierarchy order

  1. ALL
  2. TRACE
  3. DEBUG
  4. INFO
  5. WARN
  6. ERROR
  7. FATAL
  8. OFF
清眉祭 2024-12-16 15:57:00

需要明确的是,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.

enter image description here

寂寞笑我太脆弱 2024-12-16 15:57:00

下表说明了级别过滤的工作原理。

在表中,垂直标题显示您要在应用程序设置中配置的 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).

enter image description here

深者入戏 2024-12-16 15:57:00

跟踪 -->调试-->信息 --> 警告 -->错误 --> 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文