Hibernate,Log4j and SLF4j [closed]

2019-06-07 01:59发布

问题:

i am using log4j and i want to disable hibernate info logging, so here's what i tried, but it doesn't work and i still see the hibernate info logging:

1- log4j.properties:

log4j.rootLogger=DEBUG, stdout, rootLog
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

log4j.appender.rootLog=org.apache.log4j.RollingFileAppender
log4j.appender.rootLog.File=${user.home}/devlopmentLogs/mylog.log
log4j.appender.rootLog.MaxFileSize=10000KB
log4j.appender.rootLog.MaxBackupIndex=3
log4j.appender.rootLog.layout=org.apache.log4j.PatternLayout
log4j.appender.rootLog.layout.ConversionPattern=%p %t %c - %m%n


log4j.logger.org.hibernate=FATAL
log4j.logger.org.springframework=ERROR
log4j.logger.org.springframework.security=ERROR

2- Jars:

<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-entitymanager</artifactId>
   <version>3.6.8.Final</version>
</dependency>


 <dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.4</version>
</dependency>

<!-- concrete Log4J Implementation for SLF4J API-->

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.4</version>
</dependency>

please advise why i am still seeing the hibernate info logging, and how to turn it off ?

and do i need to exclude the slf4j-api from other hibernate dependencies ?

回答1:

found out that above configuration is correct and the changes to log4j wasn't published to classpath.



回答2:

In META-INF/persistence.xml of your project,

This line exist: property name="hibernate.show_sql" value="true"

Set value false.