title: Hibernate SQL statements are not getting logged in separate log file using log4j in spring boot application
body: <p>I have a web application in spring boot + Hibernate + Log4j deployed in JBOSS. All the hibernate sql queries are getting logged in server.log if we use "spring.jpa.show-sql = true" in application.properties. As per the  Hibernate Log4j instruction we need to turn this property to false so that sql statements will get logged in separate log file as per Log4j configuration. If we turn it to false then also sql statements are not logged in separate   log file. All other application related logs are getting logged in separate log file except hibernate logs. Please help to get this issue resolved.</p>
  
  <pre><code>Below is the entry in application.properties file.
  spring.jpa.show-sql = false
  spring.jpa.open-in-view=false
  spring.datasource.ucm.default-auto-commit=false
  spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
  spring.jpa.properties.hibernate.id.new_generator_mappings=false  
  spring.jackson.serialization.fail-on-empty-beans=false
  
  # SQL statements and parameters
  log4j.logger.org.hibernate.SQL=debug
  log4j.logger.org.hibernate.type.descriptor.sql=trace
  </code></pre>
  
  <p>Log4j2.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration  monitorInterval="30"&gt;
  
  &lt;Properties&gt;
      &lt;Property name="LOG_PATTERN"&gt;%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %p %m%n
      &lt;/Property&gt;
      &lt;Property name="APP_LOG_ROOT"&gt;c:/log/VendorPortal&lt;/Property&gt;
  &lt;/Properties&gt;
  
  &lt;Appenders&gt;
  
      &lt;Console name="console" target="SYSTEM_OUT" follow="false"&gt;
          &lt;PatternLayout pattern="${LOG_PATTERN}" /&gt;
      &lt;/Console&gt;
  
      &lt;!-- File Appender --&gt;
      &lt;RollingFile name="RollingFile"
          fileName="c:/log/vendorportal.log"
          filePattern="c:/log/vendorportal-%d{MM-dd-yyyy}.log"
          ignoreExceptions="false"&gt;
          &lt;PatternLayout&gt;
              &lt;Pattern&gt;%d %p %c{1.} [%t] %m%n&lt;/Pattern&gt;
          &lt;/PatternLayout&gt;
          &lt;Policies&gt;
              &lt;TimeBasedTriggeringPolicy /&gt;
              &lt;SizeBasedTriggeringPolicy size="100 MB" /&gt;
          &lt;/Policies&gt;
      &lt;/RollingFile&gt;
  
      &lt;Console name="STDOUT" target="SYSTEM_OUT"
          ignoreExceptions="false"&gt;
          &lt;PatternLayout pattern="%m%n" /&gt;
      &lt;/Console&gt;
  
  &lt;/Appenders&gt;
  
  &lt;Loggers&gt;
  
      &lt;Logger name="org.springframework" additivity="false"
          level="error"&gt;
          &lt;AppenderRef ref="RollingFile" /&gt;
      &lt;/Logger&gt;
  
      &lt;Logger name="org.hibernate" level="info" additivity="false"&gt;
          &lt;AppenderRef ref="RollingFile" /&gt;
      &lt;/Logger&gt;
  
      &lt;Logger name="org.hibernate.SQL" level="DEBUG"
          additivity="false"&gt;
          &lt;AppenderRef ref="RollingFile" /&gt;
      &lt;/Logger&gt;
  
      &lt;Logger name="org.hibernate.type.descriptor.sql" level="TRACE"
          additivity="false"&gt;
          &lt;AppenderRef ref="RollingFile" /&gt;
      &lt;/Logger&gt;
  
      &lt;Root level="error"&gt;
          &lt;AppenderRef ref="console" /&gt;
          &lt;AppenderRef ref="RollingFile" /&gt;
      &lt;/Root&gt;
  
  &lt;/Loggers&gt;
  
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>pom.xml</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-starter-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
               &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
  
          &lt;/dependency&gt;
      &lt;dependency&gt;
           &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-log4j2&lt;/artifactId&gt;
       &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
                  &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
  &lt;/dependency&gt;
  </code></pre>