Search code examples
javaspringspring-boothibernatelogback

Hibernate logger does not replace %s


I noticed for a while now that hibernate does not replace %s templates in log messages. Our own log message are replaced fine. My project uses spring boot (slf4j + logback included).

Hibernate info at server start looks like this:

hibernate example

Other libs are affected as well:

xnio example

Dependency graph, as requested: https://pastebin.com/b0QcBBnV


Solution

    • To configure hibernate to use slf4j, it need the following property , it need either starting the application with
        -Dorg.jboss.logging.provider=slf4j
    

    or in the Main Spring boot application class

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

    Steps taken to figure out what went on

    This is not actually an answer but some steps to troubleshoot as one of the classes above is JtaPlatformInitiator as I can't replicate it.

    • Put a breakpoint in the class JtaPlatformInitiator.org.hibernate.engine.transaction.jta.platform.internal at the following line:
        LOG.usingJtaPlatform( platform != null ? platform.getClass().getName() : "null" );
    
    • When the application starts, it is going to come to the above line.

    • Then it will reach this jboss class and you can see the unformatted string as well as params. enter image description here

    • Now once you go inside this method, it should be choosing one of them and prepare one formatted string. For me, it went to org.jboss.logging.Log4j2Logger and is concatenating correctly.

      enter image description here

    • Can you check what class selected for you in the last step?