views:

326

answers:

2

I'm using log4j in an app I'm developing to eventually run inside Tomcat/JBoss, but right now I'm running it from inside Eclipse. I've configured it to write to a ConsoleAppender using a log4j.xml file and passed it as a system property, and all of my logging output works.

The problem is that log4j spits out a bunch of bootstrap/startup garbage that I really don't need (or want) to see. For example:

log4j: Retreiving an instance of org.apache.log4j.Logger.
log4j: Setting [CoherenceMonitor] additivity to [false].
log4j: Level value for CoherenceMonitor is  [DEBUG].
log4j: Desired Level sub-class: [org.apache.log4j.Level]
log4j: CoherenceMonitor level set to DEBUG
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Setting property [target] to [System.out].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%-5p  %m%n].
log4j: Adding appender named [console] to category [CoherenceMonitor].

I get about 20 lines of this every time I run my program, and it's just noise that obscures the log data I really care about. What I want to do is suppress this output (everything that starts with "log4j: ") and only include output from my own logging statements.

I've tried everything I could find via Google and my coworkers, including setting a priority value for the org.apache category as shown below. (Regardless of the priority I set, I still get the output.)

<category name="org.apache">
    <priority value="FATAL"/>
</category>

I'm pretty novice at log4j configuration, and mine is pretty simple. I have only one appender, one logger, and this one category. Any help on getting log4j to just keep its mouth shut while it's doing setup would be much appreciated! :-)

+4  A: 

This looks like the debug from the logger itself. If you are using the XML config it looks like this:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">

Turn the debug to false.

javamonkey79
Um ... wow. I thought I had checked everything, don't know how I ever missed that. That's exactly what it was. However, I do feel somewhat better knowing that a few coworkers looked over my log4j.xml, and they didn't see it either. Thanks!
Quinn Taylor
I had just spent half a day fighting logging - otherwise I would never have known either :)
javamonkey79
+1  A: 

Besides checking if your log4j.xml has the debug="true" attribute, also make sure that you do not have the log4j.debug system parameter set (in Eclipse this would appear in the Run Configuration as JVM argument with the value of -Dlog4j.debug).

matt b
Also an excellent suggestion. Although my problem was in the log4j.xml, it's very useful to know where to look if the problem were to happen only in Eclipse. Thanks!
Quinn Taylor