You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Jesus M. Salvo Jr." <je...@migasia.com> on 2003/06/03 09:52:53 UTC

[Commons-Logging] Using Commons-Logging with an older Log4J ( 1.1.3 )

I am using Commons-Logging against Log4J 1.1.3

I use Commons-Logging like this:

*) via System properties:
-Dlog4j.configuration=/export/softgame/app_gateway/prod/test/log4j.properties
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog

*) within source code:
    Log     logger = LogFactory.getLog( "SMimeFetcher" );

I presume that the String passed in becomes the category name in Log4J.
The calls to info() does get outputted via Log4J, ... but they all get 
logged to Log4J's root category!

Interestingly though, I looked at the source code for 
org.apache.commons.logging.impl.Log4JCategoryLog, and there is no 
reference to Log4J's Category class, but instead it references Log4J's 
Logger class.

However, Log4J 1.1.3 did not yet have Log4J's Logger class. In short, I 
would have expected it to NOT work, but it still did.


Anyway ... is there any other alternative to reliably using 
Commons-Logging against Log4J apart from upgrading to the latest Log4J?






Re: [Commons-Logging] Using Commons-Logging with an older Log4J ( 1.1.3 )

Posted by "Jesus M. Salvo Jr." <je...@migasia.com>.
Craig R. McClanahan wrote:

>On Tue, 3 Jun 2003, Jesus M. Salvo Jr. wrote:
>
>  
>
>>Date: Tue, 03 Jun 2003 17:52:53 +1000
>>From: Jesus M. Salvo Jr. <je...@migasia.com>
>>Reply-To: Jakarta Commons Users List <co...@jakarta.apache.org>
>>To: commons-user@jakarta.apache.org
>>Subject: [Commons-Logging] Using Commons-Logging with an older Log4J (
>>    1.1.3 )
>>
>>
>>I am using Commons-Logging against Log4J 1.1.3
>>
>>I use Commons-Logging like this:
>>
>>*) via System properties:
>>-Dlog4j.configuration=/export/softgame/app_gateway/prod/test/log4j.properties
>>-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog
>>
>>*) within source code:
>>    Log     logger = LogFactory.getLog( "SMimeFetcher" );
>>
>>I presume that the String passed in becomes the category name in Log4J.
>>The calls to info() does get outputted via Log4J, ... but they all get
>>logged to Log4J's root category!
>>
>>Interestingly though, I looked at the source code for
>>org.apache.commons.logging.impl.Log4JCategoryLog, and there is no
>>reference to Log4J's Category class, but instead it references Log4J's
>>Logger class.
>>
>>However, Log4J 1.1.3 did not yet have Log4J's Logger class. In short, I
>>would have expected it to NOT work, but it still did.
>>
>>    
>>
>
>Direct calls to Log4J will, of course, work fine as long as you use Log4J
>1.1 compatible APIs.  But for the commons-logging wrappers, this depends
>on your definition of "works".  
>

It was logging to the appender defined for the root category, which is a 
file named as /var/log/Unconfigured.log in the log4j.properties.

>Commons Logging decides whether
>Log4J is available by looking for the existence of the
>org.apache.log4j.Logger class in the class path available to your
>application.  If it's not there (as would be true in your case), Commons
>Logging will simply assume that Log4J is not available, and default to JDK
>1.4 logging (if you're using JDK 1.4) or SimpleLog (if you're not).
>  
>

OK ... So I must be using SimpleLog, since I am using JDK 1.3. I'll 
check again.

>  
>
>>Anyway ... is there any other alternative to reliably using
>>Commons-Logging against Log4J apart from upgrading to the latest Log4J?
>>
>>    
>>
>
>The Commons-Logging integrated support for Log4J requires Log4J 1.2 or
>later.
>

Thanks

>
>Craig
>
>  
>


Re: [Commons-Logging] Using Commons-Logging with an older Log4J ( 1.1.3 )

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Tue, 3 Jun 2003, Jesus M. Salvo Jr. wrote:

> Date: Tue, 03 Jun 2003 17:52:53 +1000
> From: Jesus M. Salvo Jr. <je...@migasia.com>
> Reply-To: Jakarta Commons Users List <co...@jakarta.apache.org>
> To: commons-user@jakarta.apache.org
> Subject: [Commons-Logging] Using Commons-Logging with an older Log4J (
>     1.1.3 )
>
>
> I am using Commons-Logging against Log4J 1.1.3
>
> I use Commons-Logging like this:
>
> *) via System properties:
> -Dlog4j.configuration=/export/softgame/app_gateway/prod/test/log4j.properties
> -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog
>
> *) within source code:
>     Log     logger = LogFactory.getLog( "SMimeFetcher" );
>
> I presume that the String passed in becomes the category name in Log4J.
> The calls to info() does get outputted via Log4J, ... but they all get
> logged to Log4J's root category!
>
> Interestingly though, I looked at the source code for
> org.apache.commons.logging.impl.Log4JCategoryLog, and there is no
> reference to Log4J's Category class, but instead it references Log4J's
> Logger class.
>
> However, Log4J 1.1.3 did not yet have Log4J's Logger class. In short, I
> would have expected it to NOT work, but it still did.
>

Direct calls to Log4J will, of course, work fine as long as you use Log4J
1.1 compatible APIs.  But for the commons-logging wrappers, this depends
on your definition of "works".  Commons Logging decides whether
Log4J is available by looking for the existence of the
org.apache.log4j.Logger class in the class path available to your
application.  If it's not there (as would be true in your case), Commons
Logging will simply assume that Log4J is not available, and default to JDK
1.4 logging (if you're using JDK 1.4) or SimpleLog (if you're not).

>
> Anyway ... is there any other alternative to reliably using
> Commons-Logging against Log4J apart from upgrading to the latest Log4J?
>

The Commons-Logging integrated support for Log4J requires Log4J 1.2 or
later.

Craig