0

I want to include an external library in my Java project, and this library in particular uses Apache Commons Logging to write messages to the logging system. The library writes a lot of messages of level "info", causing a lot of useless entries in the logs.

My application is supposed to be deployed and executed in a shared environment (for example, tomcat or jetty). My question is, what options do I have to configure the log level for this library if I cannot rely on properties/xml configuration files?

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
Erik
  • 9
  • 1

1 Answers1

3

Apache Commons Logging is not really a logging library, it's just a facade that delegates to the underlying logging library like Log4J or java.util.logging. So first you have to discover which library are you actually using. Depending on that different configuration options apply.

My suggestion is to add replace commons-logging.jar with SLF4J bridge and then use whichever framework you want.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • 1
    I suggest looking at LogBack for the SLF4J implementation. – GreyBeardedGeek Nov 30 '12 at 22:06
  • There is a mismatch between SLF4J and JCL. In JCL (and Log4J) the logged object is an java.lang.Object, but in SLF4J (and Logback) it is a java.lang.String. If he used JCL for passing objects to listeners, by using the SLF4J bridge he loses the objects (a String.valueOf() is called in the bridge). – Amir Pashazadeh Nov 30 '12 at 22:07
  • @AmirPashazadeh: interesting, but isn't this what ultimately every logging framework has to do? I mean call `.toString()` on the object? – Tomasz Nurkiewicz Nov 30 '12 at 22:10
  • SLF4J bridge looks very promising, I'll try it and I'll be back to this forum to let you know. – Erik Dec 01 '12 at 10:08