3
votes

We are migrating from log4j to log4j2. We use the following libraries and there logging mechanisms:

Tomcat (which uses JULI), Spring 4.2.0 (which uses commons-logging) and Hibernate 4.3.11-Final (which uses jboss-logging).

I have successfully got Spring bridging to log4j2, but Hibernate logging is not working.

According to the Hibernate docs:

To use JBoss Logging with Log4j2, the log4j2 jar would also need to be available on the classpath.

I have the following logging-related jars on my classpath:

  • commons-logging-1.2.jar
  • jboss-logging-3.1.3.GA.jar
  • jboss-logging-annotations-1.2.0.Beta1.jar
  • log4j-api-2.6.1.jar
  • log4j-core-2.6.1.jar
  • log4j-jcl-2.6.1.jar
  • log4j-slf4j-impl-2.6.1.jar
  • slf4j-api-1.7.5.jar
  • slf4j-log4j12-1.7.5.jar

Any ideas why I'm not seeing the results I expect?

1
I found where i got the code from my answer from : it is a possible duplicate of Log4j2/JPA/Hibernate logging is not workingThierry

1 Answers

5
votes

The version of jboss-logging included with hibernate-4 is not compatible with log4j2.

I had to import version 3.3.0.Final (should work starting with 3.1.4, according to JBLOGGING-94) for hibernate to work with log4j2.

Here is a shortcut if you use maven :

<dependency> <!-- version working with log4j2 -->
    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <version>3.3.0.Final</version>
    <scope>runtime</scope>
</dependency>