开发者

How to use SLF4J Log4jLoggerAdapter

I'm deploying an enterprise application on Weblogic 8.1 which has log4j 1.2.8 on it's classpath. I'm getting the following error with SLF4J 1.6.1:

SLF4J versions 1.4.0 and later requires log4j 1.2.12 or later

http://www.开发者_如何学JAVAslf4j.org/codes.html#log4j_version

Above link recommends using Log4jLoggerAdapter.

I've changed

Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World");

to

Log4jLoggerAdapter logger = (Log4jLoggerAdapter) LoggerFactory.getLogger(HelloWorld.class);
logger.info("Hello World");

However, I'm still encountering the error. Any advice on how to correctly implement this?

Thanks.

[edit] slf4j-api-1.6.1.jar and slf4j-log4j12-1.6.1.jar are on my development classpath, and packaged into APP-INF/lib of my EAR file. log4j 1.2.8 is on application server's classpath.


The problem is you have to use the same slf4j-api JAR and implementation JAR (slf4j-log4j).

Make sure both jars on your CLASSPATH are the same version. Also always put only two of them:

  • the API JAR
  • an implementation JAR (e.g. log4j adapter, juli logger, simple logger...)

Edit: Looking on your error message again: You will probably need to either upgrade your log4j library or downgrade your slf4j library. They are in incompatible versions.


The "SLF4J versions 1.4.0 and later requires log4j 1.2.12 or later" is only a warning. SLF4J 1.6.1 should work just fine with log4j 1.2.8. In other words, you don't have to change anything. In particular, casting to Log4jLoggerAdapter is unnecessary, it will not help in any way except make your code uglier.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜