简体   繁体   中英

using slf4j with log4j2

I have been trying log4j2 recently. Now, I would like to test it with slf4j and wondering if all the functionality in log4j2 (eg async logging via disruptor) will be available if I try slf4j with log4j2. I have tried adding the slf4j jar files and log4j2 & disruptor jar files to a test project (I added the log4j-slf4j jar but not completely sure if its only meant for log4j or for log4j2 as well). When I use log4j2, I can log out statements to the log file. When I try slf4j, it does not work (and I'm not sure if its my config or the fact that slf4j is not setup to work with log4js disruptor logging? Any suggestions would be welcome. I will update the post with more info and sample code as well.

Yes, async loggers via the disruptor should work whether your app uses the log4j2 api, the slf4j api or the log4j-1.2 api. See the log4j2 FAQ page for which jars to include. You'll need a jar for the slf4j api, and in addition you'll need the log4j-api-2.x, log4j-core-2.x and log4j-slf4j-impl-2.x jars. The same log4j2.xml config file should work.

Update: not all Log4j2 functionality is available via the SLF4J API .

Update 2: Is it safe to program directly to the Log4j2 API?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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