views:

267

answers:

1

I got an application running in a jboss container using hibernate. However I'm having trouble with the logging that hibernate is doing. I get these startup messages when Hibernate initialises:

2010-01-08 17:23:42,017 INFO  [Configuration:1403] - Configuration resource: /hibernate.cfg.xml
2010-01-08 17:23:42,070 INFO  [Configuration:1541] - Configured SessionFactory: null

And so on. However I'd like to get rid of them since it's useless information. I have the following configuration in my log4j.properties:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c{1}:%L] - %m%n

log4j.rootCategory = error, stdout

# Hibernate
log4j.logger.org.hibernate=error
log4j.logger.org.hibernate.tool.hbm2ddl=fatal

As you can see the logging does match the format specified in my ConversionPattern. However I'm still getting INFO messages. I'm also using the Asterisk-Java API:

# Asterisk java
log4j.logger.org.asteriskjava=error

That does work properly as I only get errors:

2010-01-08 17:31:46,948 ERROR [AgiConnectionHandler:156] - AgiException running AgiScript com.**** on Asterisk-Java DaemonPool-1-thread-2 org.asteriskjava.fastagi.AgiException: Number is on blacklist

so I'm a bit confused now.

Update

When running the container with

-Dlog4j.debug

I get:

log4j: Reading configuration from URL jar:file:*******.jar!/log4j.properties
log4j: Parsing for [root] with value=[error, stdout].
log4j: Level token is [error].
log4j: Category root set to ERROR
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d %-5p [%c{1}:%L] - %m%n].
log4j: End of parsing for "stdout".
log4j: Parsed "stdout" options.
log4j: Parsing for [org.hibernate.tool.hbm2ddl] with value=[error].
log4j: Level token is [error].
log4j: Category org.hibernate.tool.hbm2ddl set to ERROR
log4j: Handling log4j.additivity.org.hibernate.tool.hbm2ddl=[null]
log4j: Parsing for [org.hibernate] with value=[fatal].
log4j: Level token is [fatal].
log4j: Category org.hibernate set to FATAL
log4j: Handling log4j.additivity.org.hibernate=[null]
log4j: Parsing for [org.asteriskjava] with value=[error].
log4j: Level token is [error].
log4j: Category org.asteriskjava set to ERROR
log4j: Handling log4j.additivity.org.asteriskjava=[null]
log4j: Finished configuring.

No other files are being loaded whatsoever. So I wonder why it doesn't work. Also I tried the following before creating the session factory:

Logger.getLogger("org.hibernate").setLevel(Level.ERROR);

No success either...

+1  A: 

Sounds like another logging configuration somewhere might be overriding yours. You might want to try adding the system variable -Dlog4j.debug to your container's startup path so that log4j will print out it's debugging information, which will tell you exactly which file it is using to configure itself. It's possible that another file on the classpath is being used instead of yours.

Also, you really shouldn't use %L in any sort of production environment - the Javadoc explicitly warns against this:

%L:
Used to output the line number from where the logging request was issued.
WARNING Generating caller location information is extremely slow. It's use should be avoided unless execution speed is not an issue.

matt b
I had some thoughts about that yes, I will try your suggestion. I'm aware of the %L issue, I have separate files for production/development
Matthias van der Vlies
I've updated my question with the result of your suggestion
Matthias van der Vlies