views:

84

answers:

3

How can I best prevent these libraries from flooding my own apps log4j bus? I do not want to set everything to ERROR, but at this rate the vendor library is flooding up the log file at a rate of about a gig/day. I do not want it to log anything to this file...

+7  A: 

Is the vendor using categories reasonably? If so, set just their root category to ERROR and leave everything else as normal. That way you should be able to filter out their non-error messages but still see your own info/debug/etc.

That's most of the point of categories :)

Jon Skeet
Seriously, I think the answer is just ... use the log4j configuration.
matt b
A: 

Eh, if all else fails you could extend LogImpl and have it inject a property into all of your logging calls and set a PropertyFilter on all of your appenders. Hope it wouldn't come to that, though.

(mind you, this is coming from log4net - I assume it all works mostly the same, but I'm just shooting from the hip)

JamesG
+2  A: 

As suggested by Jon Skeet´s answer, you should configure log4j to ignore the classes from the vendor library. Usually there is a file named log4j.xml that one can put the package names and the threshold category to print like this:

   <category name="httpclient.wire">
      <priority value="INFO"/>
   </category>

   <category name="org.apache.commons.httpclient">
      <priority value="WARN"/>
   </category>

   <category name="org.hibernate">
      <priority value="DEBUG"/>
   </category>

   <category name="net.sf.jasperreports">
      <priority value="ERROR"/>
   </category>

Take a look at the manual for details.

Leonel Martins