简体   繁体   English

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

[英]what is the difference between Log4j 2 SLF4J Binding and Log4j 2 to SLF4J Adapter

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 Binding,何时更好地使用Log4j 2到SLF4J适配器?

Its simple really. 它真的很简单。

The log4j2-slf4j binding log4j-slf4j-impl-2.3.jar routes calls from slf4j to log4j2. log4j2-slf4j绑定log4j-slf4j-impl-2.3.jar将调用从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. 这对于log4j2来说不太常用,但对于旧框架则更为常见。 It is useful whenever you have an existing application coded using the log4j2 framework but wish to use another framework. 只要您使用log4j2框架编码现有应用程序但希望使用其他框架,它就很有用。 By using this adapter you route calls from log4j2 to slf4j. 通过使用此适配器,您可以将调用从log4j2路由到slf4j。 slf4j can then route those calls to any compatible implementation as discussed in the first case. 然后,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 但是,如果使用现有的日志记录实现,它可能需要比第二次重构更多的重构

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM