当前位置: 动力学知识库 > 问答 > 编程问答 >

logging - How to use log4 and logback together?

问题描述:

In my project I use customer libraries. Inside these libraries use log4j.

I like logback. Is it possible to use slf4j in my project at this case?

I want to use all features of logback, especially dynamic configuration update.

网友答案:

I assume you mean those libraries you use have explicit calls to log4j Loggers.

In that case, using slf4j + logback as your logging implementation and including the log4j calls is quite simple.

As the slf4j documentation says, you just have to replace all the log4j dependencies with a single one from slf4j, named log4j-over-slf4j: http://slf4j.org/legacy.html#log4j-over-slf4j.

In case you are using maven the correct dependency is:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>log4j-over-slf4j</artifactId>
    <version>1.7.21</version>
</dependency>

Any code that is under your direct control can just use slf4j + logback as it always would.

分享给朋友:
您可能感兴趣的文章:
随机阅读: