3 Replies Latest reply on Sep 29, 2011 7:27 AM by are.tysnes

    JBoss 7 + Hibernate 4 + Log4j and application logging

    are.tysnes

      To get access to the hibernate logging I have to do one of the following:

       

      1) If I only want the sql's (without parameters) the following properties in the persistence.xml of my application will do the trick:

       

      <property name="hibernate.show_sql" value="true"/>

      <property name="hibernate.format_sql" value="true"/>

       

      The output is located in the console and server.log

       

      2) If I want detailed (DEBUG) information from Hibernate I have to define a log category in the JBoss console:

       

      Name: org.hibernate

      Log Level: DEBUG

       

      I can add a handler to route this log to i.e. mylog.log (not possible to change the name of this file for some reason, but I can live with that)

       

      This is OK, but not good enough!

       

      I want to define the following in my log4j.properties in my application and route the hibernate logging wherever I want i.e.:

       

      log4j.appender.HIBERNATE=org.apache.log4j.DailyRollingFileAppender

      log4j.appender.HIBERNATE.File=${jboss.server.log.dir}/hibernate.log

      log4j.appender.HIBERNATE.Append=true

      log4j.appender.HIBERNATE.DatePattern='.'yyyy-MM-dd-HH

      log4j.appender.HIBERNATE.layout=org.apache.log4j.PatternLayout

      log4j.appender.HIBERNATE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %40.40c.%-20.20M(%3.3L) %-6.6p:%m%n

       

       

      log4j.rootLogger=DEBUG, HIBERNATE

      log4j.logger.org.hibernate=DEBUG

      log4j.logger.org.hibernate.type=ALL

       

      This ha no effect and nothing is logged in hibernate.log coming from hibernate

       

      I also tried to include the following in the pom.xml:

       

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-api</artifactId>

          <version>1.6.1</version>

          <type>jar</type>

      </dependency>

      <dependency>

          <groupId>org.slf4j</groupId>

          <artifactId>slf4j-log4j12</artifactId>

          <version>1.6.0</version>

      </dependency>

       

      still no success...

       

      Anyone managed to get the hibernate logs controlled by your applications log4j ?