3 Replies Latest reply on Jan 12, 2009 4:51 AM by Gert Leenders

    Hibernate and log4j

    Gert Leenders Newbie

      I'm currently struggling a little bit with the combination of hibernate and logging in the jbp-jpd-3.2.3 suite. I'm not really familiar with log4j and all I want to do is to log the DML statements (but also nothing more or less then that).
      I haven't touched the logging setting in hibernate.cfg.xml because I'm pretty sure they are just fine , but I include them just for completeness.

      <!-- logging properties (begin) ===
       <property name="hibernate.show_sql">true</property>
       <property name="hibernate.format_sql">true</property>
       <property name="hibernate.use_sql_comments">true</property>
       ==== logging properties (end) -->

      To adapt log4j I've copied the log4j.xml file from the folder: jbpm-jpdl-3.2.3\deploy to jbpm-jpdl-3.2.3\server\server\jbpm\conf and renamed it to jboss-log4j.xml.
      I also changed the file a little bit according to my requirements, But the logger still shows me the wrong information --> the transaction info is still shown and on the other hand it misses the binding parameters information.
      Can some help me to configure log4j? Thanks.

      jboss-log4j.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
      
      <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
      
       <!-- Usage: replace the log4j.xml file in the conf directory of your jboss server
       configuration with this file
       Contents: This configuration file will log only to standard output and it will
       put the jBPM logs to level TRACE.
       -->
      
       <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
       <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
       <param name="Target" value="System.out"/>
       <param name="Threshold" value="TRACE"/>
       <layout class="org.apache.log4j.PatternLayout">
       <!-- The default pattern: Date Priority [Category] Message\n -->
       <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
       </layout>
       </appender>
      
       <!--
       <category name="org.jbpm"><priority value="INFO"/></category>
       -->
      
       <category name="org.apache"><priority value="INFO"/></category>
       <category name="org.apache.myfaces"><priority value="TRACE"/></category>
       <category name="org.jboss"><priority value="INFO"/></category>
       <category name="org.hibernate"><priority value="INFO"/></category>
       <category name="org.hibernate.SQL"><priority value="DEBUG"/></category>
       <category name="org.hibernate.transaction"><priority value="INFO"/></category>
       <category name="org.hibernate.type"><priority value="DEBUG"/></category>
       <category name="net.sf"><priority value="INFO"/></category>
      
       <root>
       <appender-ref ref="CONSOLE"/>
       </root>
      
      </log4j:configuration>

      Log snapshot:

      .JDBCTransaction@1dd040a
      16:14:10,801 DEBUG [DbPersistenceService] closing hibernate session
      16:14:10,801 DEBUG [Services] closing service 'tx': org.jbpm.tx.TxService@f60f20
      16:14:10,801 DEBUG [JobExecutorThread] obtained lock on jobs: []
      16:14:10,801 DEBUG [JbpmContextInfo] creating jbpm context with service factories '[message, tx, sc
      eduler, authentication, persistence, logging]'
      16:14:10,801 DEBUG [JbpmContext] creating org.jbpm.JbpmContext@5b38d6
      16:14:10,817 DEBUG [DbPersistenceServiceFactory] creating persistence service
      16:14:10,817 DEBUG [DbPersistenceService] creating hibernate session
      16:14:10,817 DEBUG [DbPersistenceService] beginning hibernate transaction
      16:14:10,817 DEBUG [DbPersistenceService] begun hibernate transaction org.hibernate.transaction.JDB
      Transaction@179d47f
      16:14:10,817 DEBUG [SQL] select * from ( select job0_.ID_ as ID1_26_, job0_.VERSION_ as VERSION3_26
      , job0_.DUEDATE_ as DUEDATE4_26_, job0_.PROCESSINSTANCE_ as PROCESSI5_26_, job0_.TOKEN_ as TOKEN6_2
      _, job0_.TASKINSTANCE_ as TASKINST7_26_, job0_.ISSUSPENDED_ as ISSUSPEN8_26_, job0_.ISEXCLUSIVE_ as
      ISEXCLUS9_26_, job0_.LOCKOWNER_ as LOCKOWNER10_26_, job0_.LOCKTIME_ as LOCKTIME11_26_, job0_.EXCEPT
      ON_ as EXCEPTION12_26_, job0_.RETRIES_ as RETRIES13_26_, job0_.NAME_ as NAME14_26_, job0_.REPEAT_ a
       REPEAT15_26_, job0_.TRANSITIONNAME_ as TRANSIT16_26_, job0_.ACTION_ as ACTION17_26_, job0_.GRAPHEL
      MENTTYPE_ as GRAPHEL18_26_, job0_.GRAPHELEMENT_ as GRAPHEL19_26_, job0_.NODE_ as NODE20_26_, job0_.
      LASS_ as CLASS2_26_ from JBPM_JOB job0_ where (job0_.LOCKOWNER_ is null or job0_.LOCKOWNER_=?) and
      ob0_.RETRIES_>0 and job0_.ISSUSPENDED_<>1 order by job0_.DUEDATE_ asc ) where rownum <= ?
      16:14:10,817 DEBUG [JbpmContext] closing jbpmContext org.jbpm.JbpmContext@5b38d6
      16:14:10,817 DEBUG [Services] closing service 'persistence': org.jbpm.persistence.db.DbPersistenceS
      rvice@56291a
      16:14:10,817 DEBUG [DbPersistenceService] committing hibernate transaction org.hibernate.transactio
      .JDBCTransaction@179d47f
      16:14:10,817 DEBUG [DbPersistenceService] closing hibernate session
      16:14:10,817 DEBUG [Services] closing service 'tx': org.jbpm.tx.TxService@a4911d


        • 1. Re: Hibernate and log4j
          Ronald van Kuijk Master

           

          I'm currently struggling a little bit with the combination of hibernate and logging in the jbp-jpd-3.2.3 suite.


          You can't since it is jbpm-jpdl-3.2.3 ;-)


          I haven't touched the logging setting in hibernate.cfg.xml because I'm pretty sure they are just fine , but I include them just for completeness.
          <!-- logging properties (begin) ===
           <property name="hibernate.show_sql">true</property>
           <property name="hibernate.format_sql">true</property>
           <property name="hibernate.use_sql_comments">true</property>
           ==== logging properties (end) -->


          You say you don't know log4j, but do you know xml? The parameters are *commented out*. Search on comment in this page http://www.w3schools.com/Xml/xml_syntax.asp

          • 2. Re: Hibernate and log4j
            Martin Weiler Apprentice

             

            "glnd" wrote:
            on the other hand it misses the binding parameters information.
            Can some help me to configure log4j? Thanks.


            The log4j settings are correct. The binding parameters aren't shown because of this bug:
            http://opensource.atlassian.com/projects/hibernate/browse/HHH-2835

            The workaround is to replace server/jbpm/lib/commons-logging.jar (which is version 1.1.0) with an older commons-logging 1.0.x version.

            • 3. Re: Hibernate and log4j
              Gert Leenders Newbie

              Thanks a lot kukeltje, indeed i missed the fact that the parameters where commented out.
              But that only solved my problem partially.

              So also thanks to mputz. The replacement of the commons-logging.jar solved the rest of the problem!

              I also changed the jboss-log4j.xml a little bit so that all sql is logged into a separate file. (Based on this article: http://hibernar.org/articulos_en/logging.php)

              This is how my jboss-log4j.xml looks now:

              <?xml version="1.0" encoding="UTF-8" ?>
              <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
              
              <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
              
               <appender name="appenderConsole" class="org.apache.log4j.ConsoleAppender">
               <layout class="org.apache.log4j.SimpleLayout"/>
               </appender>
              
               <appender name="appenderNormalFile" class="org.apache.log4j.RollingFileAppender">
               <param name="File" value="${jboss.server.log.dir}/normal.log"/>
               <param name="Append" value="true"/>
               <param name="MaxFileSize" value="500KB"/>
               <param name="MaxBackupIndex" value="1"/>
               <layout class="org.apache.log4j.PatternLayout">
               <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
               </layout>
               </appender>
              
               <appender name="appenderSQLFile" class="org.apache.log4j.RollingFileAppender">
               <param name="File" value="${jboss.server.log.dir}/sql.log"/>
               <param name="Append" value="true"/>
               <param name="MaxFileSize" value="500KB"/>
               <param name="MaxBackupIndex" value="1"/>
               <layout class="org.apache.log4j.PatternLayout">
               <param name="ConversionPattern" value="%d %m%n"/>
               </layout>
               </appender>
              
               <category name="org.hibernate.SQL" additivity="false">
               <priority value="debug" />
               <appender-ref ref="appenderConsole" />
               <appender-ref ref="appenderSQLFile" />
               </category>
              
               <category name="org.hibernate.type" additivity="false">
               <priority value="debug" />
               <appender-ref ref="appenderConsole" />
               <appender-ref ref="appenderSQLFile" />
               </category>
              
               <root>
               <priority value="info" />
               <appender-ref ref="appenderConsole" />
               <appender-ref ref="appenderNormalFile" />
               </root>
              
              </log4j:configuration>