Log4J- Properly configuring output to a file

I am using JDK 1.5 with release 6.0.4.

I am able to get log4j to work correctly using 6.0.4 with JDK 1.4, but not with 1.5.

I have a few issues with this:
1. I cannot get log4j to write to a file, only to the Intellij Output console. Here is my log4j file. I am using a RollingFileAppender, so I am wondering how my out put is ending up in the console instead of a file.
log4j.rootLogger=INFO, veriforceapp
log4j.appender.veriforceapp=org.apache.log4j.RollingFileAppender
log4j.appender.veriforceapp.File=VeriforceApplication.log
log4j.appender.veriforceapp.Threshold=INFO
log4j.appender.veriforceapp.layout=org.apache.log4j.PatternLayout
log4j.appender.veriforceapp.layout.ConversionPattern=%d %5p %c:%L - %m%n
log4j.appender.veriforceapp.MaxFileSize=10MB
log4j.appender.veriforceapp.MaxBackupIndex=10

2. I have a lot of information being output to the console, more specifically, Hibernate and Apache debug statements. How do I turn these off?
2007-02-26 10:09:27,384 DEBUG - ]]>
2007-02-26 10:09:27,400 DEBUG - ]]>
2007-02-26 10:09:27,400 WARN - ]]>
2007-02-26 10:09:27,447 DEBUG - <Disk Store Path: C:\DOCUME1\nweedle\LOCALS1\Temp\>
2007-02-26 10:09:28,181 DEBUG - ]]>
2007-02-26 10:09:28,181 DEBUG - ]]>
2007-02-26 10:09:28,181 DEBUG - ]]>
2007-02-26 10:09:28,228 DEBUG - ]]>
2007-02-26 10:09:28,228 DEBUG - ]]>
2007-02-26 10:09:28,228 DEBUG - ]]>
2007-02-26 10:09:28,447 DEBUG - ]]>
2007-02-26 10:09:28,447 DEBUG - ]]>
2007-02-26 10:09:28,462 DEBUG - ]]>
2007-02-26 10:09:28,462 DEBUG - ]]>
2007-02-26 10:09:28,462 DEBUG - ]]>
2007-02-26 10:09:28,462 DEBUG - ]]>
2007-02-26 10:09:28,462 DEBUG - ]]>
2007-02-26 10:09:28,478 DEBUG - ]]>
2007-02-26 10:09:28,478 DEBUG - ]]>
2007-02-26 10:09:28,478 DEBUG - ]]>
2007-02-26 10:09:28,478 DEBUG - ]]>
2007-02-26 10:09:28,478 DEBUG - ]]>
2007-02-26 10:09:28,494 DEBUG - ]]>
2007-02-26 10:09:28,494 DEBUG [

4 comments
Comment actions Permalink

would it be possible that another log4j.properties file would be used instead of yours ?
The pattern does not seem to match as far as I can see. (especially the %c does not match the package names I think ?no line numbers are shown and the class name should not be between [])

You may try something like

URL log4j = MyMainClass.class.getResource("/log4j.properties");
System.out.println("log4j found " + log4j.toExternalForm());

Where MyMainClass is one of the classes of your application. This should show the url of the file used for log4j configuration.

0
Comment actions Permalink

Thibaut,

Thanks, that's what I needed!

I am using hyperjaxb(XML Beans to Hibernate objects) and there was a JAR file used for running one of it's tests, and that had a log4j.properties file that was being picked up before my properties file. I was suffering from some tunnel vision and you pointed me in the right direction. Thank you!

Nathan

0
Comment actions Permalink

>2. I have a lot of information being output to the console, more specifically, Hibernate and Apache debug statements. How do I turn these off?

You turn down the logging for the packages in question, by adjusting the loggers additivity as so:

In log4j XML format, if you wanted to turn packages below org.hibernate to WARN, you would do something like:

]]>

In properties format I believe it is (but I have not used this form in some time):

log4j.logger.org.hibernate=WARN

0
Comment actions Permalink

you're welcome :)

As you can guess, I have encountered this problem so many times I found a solution for it ;)

0

Please sign in to leave a comment.