dublintech
dublintech

Reputation: 17785

Hibernate logging driving me crazy

I am using hibernate 3.2.5.ga and having sever difficult setting up log4j logging. I have tried everything in this thread: Configuring Hibernate logging using Log4j XML config file?

In summary: here is my log4j.xml

in my hibernate.properties I have

<appender name="HibernateAppender" class="org.apache.log4j.FileAppender">
    <param name="File" value="hibernate.log" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %-5p [%t] [Acc=%X{MDCKey.Account}] [Oppo=%X{MDCKey.Opportunity}] [URL=%X{MDCKey.Url}] [Dest=%X{MDCKey.Dest}] (%F:%L) - %m%n"/>
    </layout>       
</appender>
<logger name="org.hibernate">
<level value="debug" />
<appender-ref ref="HibernateAppender"/>
</logger>

<root>
    <priority value="info" />
    <appender-ref ref="Log"/>
    <appender-ref ref="DailyRollover"/>
    <appender-ref ref="ErrorCaptureAppender"/>
</root>

In my hibernate.properties I also set:

hibernate.show_sql true

When I debug the code, I see hibernate delegate its logging to slf4j classes. When I debug these classes I see empty implementation of methods. For example: org.slf4j.impl.NOPLogger has empty implementation for its log methods. I think this the problem.

In my maven I have :

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.5.2</version>
      <optional>false</optional>
    </dependency>

So this is the version of slf4j I am using. Note, I have tried various configurations for the log4j.xml for example explictly adding the appender to the root. Just really stuck.

Any tips?

Upvotes: 0

Views: 521

Answers (1)

Ken Chan
Ken Chan

Reputation: 90427

I think you miss the correct "SLF4J bindings" jar that matches your logging frameworks (i.e log4j in your case) in order to delegate all the logging calls of the SLF4J API to log4j.

Try to add the following in order to download the binding for log4j (i.e slf4j-log4j12-1.5.2.jar)

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

Of course , please also make sure that you have already included log4j in the Maven dependencies.

Upvotes: 2

Related Questions