Home > Software design >  Setting Hibernate Logging Provider with Version 6.1
Setting Hibernate Logging Provider with Version 6.1

Time:10-24

I am using Hibernate 6.1.2. I'd like to log use the default JDK logging provider. According to a documentation for 5.4, this can be done like this:

public class TestSL4JBug {
    public static void main(String[] args) {
        System.setProperty("org.jboss.logging.provider", "jdk");
        jakarta.persistence.Persistence.createEntityManagerFactory("myPersistence");        
    }
}

I looked for a similar explanation in newer documentations, but I did not find it.

Alas, if I am testing the minimal example above, I get this:

...

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
MLog initialization issue: slf4j found no binding or threatened to use its (dangerously silent) NOPLogger. We consider the slf4j library not found.

...

To me, this looks like Hibernate tries to load SLF4J and fails. I have, of course, found guides that say I should add the SLF4J dependency, but that is not what I want.

So my question is: How do I configure Hibernate 6.1.2 to log with JDK logging? Has the property changed, or should I use a better way to set it?

CodePudding user response:

I realized that it was not vanilla Hibernate that caused the error. I am also using hibernate-spatial and consequently geolatte-geom. That one is not using JBoss logging and instead always goes through SLF4J. So even though Hibernate went through JDK logging, SLF4J was still loaded. I have now unhappily added slf4j-jdk14 and the error is gone. It's still more layers and source code sources than I am happy with, but probably a lot less than in other programming ecosystems.

  • Related