0

I need to log all full queries (with parameters) in Hibernate 5. My build.gradle (dependencies):

dependencies {
    compile 'com.corundumstudio.socketio:netty-socketio:1.7.8'
    compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.21'
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
    compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
    compile 'org.hibernate:hibernate-core:5.2.5.Final'
    compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.38'
}

My log4j2-test.properties:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p [%c] - %m%n

log4j.rootLogger=info, stdout
# basic log level for all messages
log4j.logger.org.hibernate=INFO

# SQL statements and parameters
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type=ALL
log4j.logger.org.hibernate.type.descriptor.sql=trace

But Hibernate don't want to work as expected.

2 Answers 2

1

I use the XML configuration format and this works for me.

<Logger name="org.hibernate.SQL" level="debug" additivity="false">
    <AppenderRef ref="main_appender"/>
</Logger>
<Logger name="org.hibernate.type" level="trace" additivity="false">
    <AppenderRef ref="main_appender"/>
</Logger>

My guess for how it translates is to have log4j.logger.org.hibernate.type=trace

Sign up to request clarification or add additional context in comments.

Comments

1

Your dependencies are slightly wrong.

Please remove org.slf4j:slf4j-log4j12 (this is for the old Log4j 1) and add org.apache.logging.log4j:slf4j-impl.

1 Comment

That and set -Dorg.jboss.logging.provider=slf4j in the command line or call System.setProperty("org.jboss.logging.provider", "slf4j"); before Hibernate is initialized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.