views:

208

answers:

2

So we ran into an interesting issue today. We have a JEE (J2EE) web app that uses a bunch of 3rd party jars. This includes Hibernate.

We use the java logging api that comes with the SDK for logging purposes. Typically we are pretty thin on logging but we ran into this issue with one of our 3rd party jars using log4j to create it's own log file. Not only was it logging statements from it's own code, it even started writing out debugs for the hibernate code which resulted in a batch job logging 3 GB worth of logs in no time.

I have 2 issues with this:

  1. I need to fix this logging issue (If possible I do not wish to yank out or modify the log4j config in the 3rd party jar). Is there a good way to do this besides modifying or yanking out the log4j config in the 3rd party jar OR by having my own log4j config that overrides the config in the 3rd party jar? I do not like either of the 2 options but I want to do what's best.
  2. I want to ask if it is kosher to expect 3rd party libraries to be logging away merrily? I think this is bad design. I want to get the community's opinion on this.

EDIT- After looking at some of the comments. Yes, I do want the 3rd party libraries logging ERROR's. That being said I think it is slightly awkward that this 3rd party jar to log DEBUG's from packages other than the ones it is responsible for. e.g. in my case, this 3r'd party jar is logging Hibernate debugs even though it does not even call any hibernate methods. The batch job that we ran did not even call the API in this jar. It looks like having my own log4j config override what's in there seems to be the best way to go. Thanks guys!

+1  A: 

If they are using log4j or another commonly used logging framework, you can override its configuration by providing another lo4j.properties earlier on the classpath. 3rd party logging is in my opinion a good thing as long as you can easily configure the logging level that you want, which is the case if they use log4j. It's always easier to configure a logging system to output less information than to instrument 3rd party code to add logging to it !

Guillaume
+1  A: 

From what I remember you just need to provide your own log4j properties file on the classpath before your JARs that are doing the logging, and this one will be picked up. Digging back to the depths of memory, Hibernate at least picks this up from the root of its JAR, so you don't need to package your properties.

As a wider issue, yes I definitely want my libraries logging - otherwise how do you know if something has gone wrong if there's no log?

MrWiggles
I'd want them logging, but only at an ERROR level by default. 3GB of debug level logs is pretty ridiculous.
Adam Jaskiewicz
I agree with you Adam, also, I would want them logging for packages within the library, not for other packages as well. In my case this library was merrily logging away debugs for Hibernate.
Deep Kapadia