@XSlf4j和@Slf4j注解在Lombok中有什么区别?

huangapple go评论67阅读模式
英文:

What is difference between @XSlf4j and @Slf4j annotation in Lombok?

问题

请问有人能解释一下 lombok.extern.slf4j.XSlf4jlombok.extern.slf4j.Slf4j 之间的区别吗?看起来 XSlf4j 是一个新的添加,为什么将这个新注解添加到 Lombok 库中?

英文:

Can someone please explain the difference between lombok.extern.slf4j.XSlf4j and lombok.extern.slf4j.Slf4j? Looks like XSlf4j is a new addition, why was this new annotation added to Lombok library.

答案1

得分: 5

一种注解生成普通记录器,另一种生成扩展记录器。

Lombok为xslf4j注解生成以下代码(此代码来自https://projectlombok.org/api/lombok/extern/slf4j/XSlf4j):

private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);

XLogger是扩展记录器,请参阅https://www.slf4j.org/extensions.html,它具有以下摘要开始的描述:

XLogger类提供了一些额外的记录方法,非常有用于跟踪应用程序的执行路径。这些方法生成的记录事件可以与其他调试记录分开过滤。鼓励广泛使用这些方法,因为已经发现其输出有助于:

  • 在开发过程中进行问题诊断,而无需进行调试会话
  • 在生产中进行问题诊断,而无法进行调试
  • 帮助新开发人员学习应用程序。
英文:

One annotation results in a normal logger, the other results in an extended logger.

Lombok generates this code for the xslf4j annotation (this code came from https://projectlombok.org/api/lombok/extern/slf4j/XSlf4j):

 private static final org.slf4j.ext.XLogger log = org.slf4j.ext.XLoggerFactory.getXLogger(LogExample.class);

XLogger is an extended logger, see https://www.slf4j.org/extensions.html, it has a description starting with this summary:

> The XLogger class provides a few extra logging methods that are quite useful for following the execution path of applications. These methods generate logging events that can be filtered separately from other debug logging. Liberal use of these methods is encouraged as the output has been found to
>* aid in problem diagnosis in development without requiring a debug session
>* aid in problem diagnosis in production where no debugging is possible
>* help educate new developers in learning the application.

huangapple
  • 本文由 发表于 2023年7月10日 22:48:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654902.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定