How to switch Hibernate from jboss-logging to logback?

5.5k views Asked by At

I found, that my hibernate dependency caused dependency on jboss-logging in turn.

Is it possible to switch to logback logging, which I am already use?

UPDATE

I have tried three places to set org.jboss.logging.provider:

1) Lassing to JPA properties in Spring:

.setJpaProperties(additionalProperties());

2) Setting property in main():

System.setProperty("org.jboss.logging.provider", "slf4j");

3) setting property in command line:

-Dorg.jboss.logging.provider="slf4j"

Neither worked.

I am getting an exception:

Caused by: java.lang.ClassNotFoundException: org.jboss.logging.Logger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 32 more

Note, that I have excluded jboss logging from dependencies:

 <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.7.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.jboss.logging</groupId>
                <artifactId>jboss-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jboss.logging</groupId>
                <artifactId>jboss-logging-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
1

There are 1 answers

0
Imreking On

I set the property in the standalone.conf.bat file:

SET "JAVA_OPTS=%JAVA_OPTS% -Dorg.jboss.logging.provider=slf4j"

That Logger.class can be found in the jboss-logging jar in JBOSS_HOME\modules\org\jboss\logging\main folder. That module is there by default.

I had a similar problem recently. I think you will be faced with this if you solve the Logger.class problem.

I got this exception:

ClassNotFoundException: org.slf4j.LoggerFactory from [Module "org.jboss.logging:main"

I added a depenency to slf4j in my JBOSS_HOME\modules\org\jboss\logging\main\module.xml

<module xmlns="urn:jboss:module:1.1" name="org.jboss.logging">
  <resources>
      <resource-root path="jboss-logging-3.1.0.GA.jar"/>
  </resources>

  <dependencies>
     <module name="org.jboss.logmanager"/>
     <module name="org.slf4j" slot="1.7.5" />
  </dependencies>
</module>