Log4j 2 SLF4J绑定和Log4j 2到SLF4J适配器有什么区别

时间:2021-11-22 21:52:09

As the title, what is the difference between 2 of them.

作为标题,其中2个有什么区别。

And when is better to use Log4j 2 SLF4J Binding, and when is better to use Log4j 2 to SLF4J Adapter?

什么时候更好地使用Log4j 2 SLF4J绑定,何时更好地使用Log4j 2到SLF4J适配器?

1 个解决方案

#1


6  

Its simple really.

它真的很简单。

The log4j2-slf4j binding log4j-slf4j-impl-2.3.jarroutes calls from slf4j to log4j2.

log4j2-slf4j绑定log4j-slf4j-impl-2.3.jarroutes从slf4j到log4j2的调用。

This is the most common usage case. It allows you to code your application with slf4j API but use log4j2 as the underlying implementation.

这是最常见的用例。它允许您使用slf4j API编写应用程序代码,但使用log4j2作为底层实现。

The log4j2 to slf4j adapter log4j-to-slf4j-2.3.jar does the opposite it routes calls from log4j2 to slf4j.

log4j2到slf4j适配器log4j-to-slf4j-2.3.jar相反,它将从log4j2调用到slf4j。

This is much less commonly used for log4j2 but more so for older frameworks. It is useful whenever you have an existing application coded using the log4j2 framework but wish to use another framework. By using this adapter you route calls from log4j2 to slf4j. slf4j can then route those calls to any compatible implementation as discussed in the first case.

对于log4j2来说,这种情况要少得多,但对于较旧的框架则更为常见。只要您使用log4j2框架编码现有应用程序但希望使用其他框架,它就很有用。通过使用此适配器,您可以将调用从log4j2路由到slf4j。然后,slf4j可以将这些调用路由到任何兼容的实现,如第一种情况所述。

Ideally you always want the first case since it is more straight forward and efficient. However it may require much more refactoring than the second if working with an existing implementation of logging

理想情况下,您总是想要第一种情况,因为它更直接,更有效。但是,如果使用现有的日志记录实现,它可能需要比第二次重构更多的重构

#1


6  

Its simple really.

它真的很简单。

The log4j2-slf4j binding log4j-slf4j-impl-2.3.jarroutes calls from slf4j to log4j2.

log4j2-slf4j绑定log4j-slf4j-impl-2.3.jarroutes从slf4j到log4j2的调用。

This is the most common usage case. It allows you to code your application with slf4j API but use log4j2 as the underlying implementation.

这是最常见的用例。它允许您使用slf4j API编写应用程序代码,但使用log4j2作为底层实现。

The log4j2 to slf4j adapter log4j-to-slf4j-2.3.jar does the opposite it routes calls from log4j2 to slf4j.

log4j2到slf4j适配器log4j-to-slf4j-2.3.jar相反,它将从log4j2调用到slf4j。

This is much less commonly used for log4j2 but more so for older frameworks. It is useful whenever you have an existing application coded using the log4j2 framework but wish to use another framework. By using this adapter you route calls from log4j2 to slf4j. slf4j can then route those calls to any compatible implementation as discussed in the first case.

对于log4j2来说,这种情况要少得多,但对于较旧的框架则更为常见。只要您使用log4j2框架编码现有应用程序但希望使用其他框架,它就很有用。通过使用此适配器,您可以将调用从log4j2路由到slf4j。然后,slf4j可以将这些调用路由到任何兼容的实现,如第一种情况所述。

Ideally you always want the first case since it is more straight forward and efficient. However it may require much more refactoring than the second if working with an existing implementation of logging

理想情况下,您总是想要第一种情况,因为它更直接,更有效。但是,如果使用现有的日志记录实现,它可能需要比第二次重构更多的重构