1
votes

I have configured Hibernate to use logback logging library. And created an appender that catches logging data from "org.hibernate.SQL" and "org.hibernate.type" loggers. By default, those are set to INFO level.

As the next step I try to change the level of those 2 loggers to DEBUG level using JMX interface of logback. But it does not work and log file contains no data. Only if I set the logging level to DEBUG in the configuration file and then restart the server it works.

Should I do anything additional in order to make Hibernate to start logging?

Here goes the appender/logger configuration:

<configuration debug="false" scan="true" scanPeriod="5 minutes"> 

  <jmxConfigurator />

  ...

  <property name="SQL_LOG_LEVEL" value="DEBUG" />

  <appender name="SQL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
     <file>${LOG_DIRECTORY}/sql_${weblogic.Name}.log</file>
     <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>${ROTATION_DIRECTORY}/sql_${weblogic.Name}.%i.log.zip</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>5</maxIndex>
     </rollingPolicy>
     <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
        <pattern>${LOG_PATTERN}</pattern>
     </encoder>
  </appender>   

  <logger name="org.hibernate.SQL" level="${SQL_LOG_LEVEL}" additivity="false">
      <appender-ref ref="SQL_LOG" />  
  </logger>

  <logger name="org.hibernate.type" level="${SQL_LOG_LEVEL}" additivity="false">
      <appender-ref ref="SQL_LOG" />  
  </logger>                           

     ...

</configuration>

EDIT: I have several applications (EAR) files deployed on the same container. All applications are using same logging configuration.

2

2 Answers

1
votes

Problem appears to be in fact that I deploy several applications on one sever and, basically, each application's class loader has a copy of logback libraries. That's why several logging context are created, but because they all share the same name ("default"), basically, only one get registered to MBean server.

The solution could be either moving logback libraries higher in class loader hierarchy or use logger context separation as proposed by logback documentation.

0
votes

I was not able to log any output from org.hibernate.SQL and friends until I set my log level to TRACE instead of DEBUG using logback over slf4j.