我需要登錄所有的全查詢(帶參數)在休眠5 我的build.gradle(依賴):Hibernate日誌本地的SQL查詢
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'
}
我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
但是Hibernate不想按預期工作。
並在命令行中設置'-Dorg.jboss.logging.provider = slf4j'或調用'System.setProperty(「org.jboss.logging.provider」,「slf4j」);'在Hibernate初始化之前。 – coladict