commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rathert Jonas (Platinion)" <Rathert.Jo...@platinion.de>
Subject Problem understanding commons-logging default factory
Date Wed, 18 Dec 2002 12:44:29 GMT
Hi there,

I just started using log4j and commons-logging (I use 
commons-logging-1.0.2 and log4j-1.2.7) and am now stuck
with a small problem (well, it's not really a serious problem, 
but I'm curious...).

I have a commons-logging.properties file which is found at startup
of my program (this was validated by specifiying a different 
LogFactory to use JLEA [http://www.jlea.de/] - which works).

Now, from what I understand, if I do not specify any particular 
LogFactory in that file, commons-logging will choose 

  org.apache.commons.logging.impl.LogFactoryImpl

as the default factory.  If I include the log4j JAR files in 
my project (and configure log4j the right way), log4j is used 
and works perfectly.

But then I started playing around with the 

  org.apache.commons.logging.Log

property.  The documentation of the default factory says:

  "When a new Log instance must be created, the default LogFactory 
   implementation uses the following discovery process is used:

    * Look for a system property named 
        org.apache.commons.logging.Log [...]
    * Look for a configuration attribute of this factory named 
        org.apache.commons.logging.Log.
    * If the Log4J logging system is available in the application 
        class path, use the corresponding wrapper class 
        (Log4JCategoryLog).    
    [...]"

Following this, I tried to override the use of log4j by putting 
the following line into my commons-logging.properties-file:

  org.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog

No I would expect the log output to disappear (as NoOpLog just throws
away everything).  But this only happens, if I remove the log4j jar from 
my project - otherwise, still log4j is used (and the Log-property above
seems to be ignored).

Even if I define this as a system-property in my java call:

  java -Dorg.apache.commons.logging.Log=\
    org.apache.commons.logging.impl.NoOpLog ...

the behaviour is as described above: Still,log4j is used.

Is this the expected behavior (if log4j is available, always use it in
favor of all "SimpleLog" or "NoOpLog" implementations - so the docs are 
wrong here!), or did I read the wrong part of the docs? Or did I do 
any other mistake?

(Actually, I'll never use SimpleLog or NoOpLog, so it's more a 
academical kind of question, but as I said: I'm just curious. :-)

Thanks in advance

  Jonas

-- 
    Jonas Rathert | IT Architect

    PLATINION GmbH
    A Company of the Boston Consulting Group

    Im Mediapark 5, 50670 Cologne/Germany
    Tel.    +49 221. 58 95 83 04,  Mobile    +49 160. 532 13 04
    Fax     +49 221. 589 20 51
    mailto:rathert.jonas@platinion.de
    http://www.platinion.de/


Mime
View raw message