You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Rob Walker <ro...@softsell.com> on 2002/04/17 13:45:21 UTC

Common problem I'll bet

I've written a utility class and I'd like to include log4j calls for diagnostic and error 
logging.

Problem is this:

(i) At compile time, I can be sure the log4j.jar will be present.

(ii) At runtime, depending on who's using my class log4j either may not be 
present or may not be configured.

I'd like to make my utility "smart" so that it can detect (ii) and either shut-up, or 
just log out to System.err/out.

My thought was to try an initial Logger creation and catch class not found 
exception, which would seem to handle the "not present" case. Not sure if this 
will work, and whether there's any easy way to handle the "not configured" case 
(less of a problem since I could skip this step and assume that if log4J is present, 
then it should be configured).

Anyone got thoughts on this?

-- Rob Walker
SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Common problem I'll bet

Posted by Fergus Gallagher <Fe...@OrbisUK.com>.
I'm sure there are better ways, but if Log4J is not configured, then

	Category.getRoot().getAllAppenders() 

returns a NullEnumeration.

On Wed, Apr 17, 2002 at 12:45:21PM +0100, Rob Walker wrote:
> I've written a utility class and I'd like to include log4j calls for diagnostic and error 
> logging.
> 
> Problem is this:
> 
> (i) At compile time, I can be sure the log4j.jar will be present.
> 
> (ii) At runtime, depending on who's using my class log4j either may not be 
> present or may not be configured.
> 
> I'd like to make my utility "smart" so that it can detect (ii) and either shut-up, or 
> just log out to System.err/out.
> 
> My thought was to try an initial Logger creation and catch class not found 
> exception, which would seem to handle the "not present" case. Not sure if this 
> will work, and whether there's any easy way to handle the "not configured" case 
> (less of a problem since I could skip this step and assume that if log4J is present, 
> then it should be configured).
> 
> Anyone got thoughts on this?
> 
> -- Rob Walker
> SoftSell Business Systems, Ltd.
> ' testing solutions for a changing world '
>  
> +44 (20) 7488 3470
> www.softsell.com
> robw@softsell.com
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 
Fergus Gallagher          Tel: +44 (20) 8742 1600
Orbis                     Fax: +44 (20) 8742 2649
414 Chiswick High Street  email: Fergus.Gallagher@orbisuk.com
London  W4 5TL            Web: http://www.orbisuk.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Common problem I'll bet

Posted by Rob Walker <ro...@softsell.com>.
Thanks Jeff. All good thoughts.
-- Rob

Send reply to:  	"Log4J Users List" <lo...@jakarta.apache.org>
Date sent:      	Mon, 22 Apr 2002 13:09:05 +1000
From:           	Jeff Turner <je...@socialchange.net.au>
To:             	Log4J Users List <lo...@jakarta.apache.org>
Subject:        	Re: Common problem I'll bet

> This sounds like exactly what you want:
> 
> http://jakarta.apache.org/commons/logging.html
> 
> Although you should read Ceki's comments on it:
> 
> http://marc.theaimsgroup.com/?l=jakarta-general&m=101720213502190&w=2
> 
> 
> --Jeff
> 

SoftSell Business Systems, Ltd.
' testing solutions for a changing world '
 
+44 (20) 7488 3470
www.softsell.com
robw@softsell.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Common problem I'll bet

Posted by Jeff Turner <je...@socialchange.net.au>.
This sounds like exactly what you want:

http://jakarta.apache.org/commons/logging.html

Although you should read Ceki's comments on it:

http://marc.theaimsgroup.com/?l=jakarta-general&m=101720213502190&w=2


--Jeff

On Wed, Apr 17, 2002 at 12:45:21PM +0100, Rob Walker wrote:
> I've written a utility class and I'd like to include log4j calls for diagnostic and error 
> logging.
> 
> Problem is this:
> 
> (i) At compile time, I can be sure the log4j.jar will be present.
> 
> (ii) At runtime, depending on who's using my class log4j either may not be 
> present or may not be configured.
> 
> I'd like to make my utility "smart" so that it can detect (ii) and either shut-up, or 
> just log out to System.err/out.
> 
> My thought was to try an initial Logger creation and catch class not found 
> exception, which would seem to handle the "not present" case. Not sure if this 
> will work, and whether there's any easy way to handle the "not configured" case 
> (less of a problem since I could skip this step and assume that if log4J is present, 
> then it should be configured).
> 
> Anyone got thoughts on this?
> 
> -- Rob Walker
> SoftSell Business Systems, Ltd.
> ' testing solutions for a changing world '
>  
> +44 (20) 7488 3470
> www.softsell.com
> robw@softsell.com
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>