1

I have a tomcat app using hibernate. When I go into the WEB-INF and change the log4j.properties to the following...

log4j.logger.net.sf.hibernate.SQL=trace

But I am not seeing anything in the log file I am using.

log4j.rootLogger=debug, stdout
....
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=hibernate.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

Logging seems to work fine for my own app.

Any ideas?

1
  • check your hibernate config xml file.Is there 'hibernate.show_sql' property is set to false ? Commented Nov 10, 2011 at 19:33

2 Answers 2

6

Not sure on this, but I think newer Hibernate-versions might use slf4j instead of log4j. You can get past this by using a slf4j-log4j -bridge. If you're using Maven, the dependency is along the lines of

    <!-- slf4j -> log4j bridge (some libraries use slf4j) -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

Modify versions as necessary.

Sign up to request clarification or add additional context in comments.

3 Comments

I am using... <dependency> <groupId>com.googlecode.sli4j</groupId> <artifactId>sli4j-slf4j-simple</artifactId> <version>2.0</version> </dependency>
I'm not familiar with sli4j, but the website says "No setter methods are needed, no special annotations, just declare it and let sli4j doing the rest, final and already set Loggers will be skipped and sli4j won't try to override them at all.". Could the problem be that Hibernate loggers are declared as 'private static final', in which case sli4j won't inject its own loggers?
I tried adding this instead and I think it worked x2 checking
0

Try the following because hibernate is no longer under a net.sf package hierarchy:

log4j.logger.org.hibernate.SQL=trace

2 Comments

Thanks but I am using an older version.
I think that when hibernate was under net.sf it wasn't yet using slf4j. Just wondering whether you really found the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.