We do something similar for enabling logging from our signed applet.

We use commons logging and default to NoOpLog, but if a
log4j.configuration property is defined as a runtime parameter in the
plugin (and log4j.jar is in the classpath), Log4J is used as the logger
implementation.

The only dependencies in our code are commons.logging.log and
commons.logging.logfactory.

The nooplog is used if the log is set as a system property: 
"org.apache.commons.logging.Log" set to
"org.apache.commons.logging.impl.NoOpLog"

Hope that helps..

-----Original Message-----
From: Milton Smith [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, June 18, 2003 9:23 AM
To: Log4J Developers List
Subject: Re: [RT] Agnostic logging support



--- Nicola Ken Barozzi <[EMAIL PROTECTED]> wrote:
> 
> A problem with logging libraries, is that even if I
> only use the app
> without needing *any* logging, I still have to
> include the jar of the 
> logging library. And as small as it may be, it's
> still something I'd 
> like to not distribute.

One idea here.  Don't use the Log4J implementation
directly.  Make an adapter layer that calls Log4J
internally.  Then your programs call the logging
methods of your adaptors to log.  The adaptors would
compile and ship with your code.  In side the adaptors
you would use reflection to access Log4J.  In this way
you can choose to ship the Log4J jar or not.  Also the
adaptors could access other logging systems if needed.
 Since everything uses reflection there would not be
any compile errors if any jars are not present.

> 
> Then the problem of the logging library. Some want
> Jakarta Commons
> Logging, some JDK1.4 logging, some their system.
> Mind me, I understand 
> that it's easy to make log4j output to their logging
> system, but it 
> seems that some are really stuck to having to use
> their system throughout.

See above.

> 
> Finally, there is the speed issue. As fast as an
> if.isDebugEnabled() may
> be, we have seen that some places need a logging
> statement in a "close 
> loop", and this makes performance degrade.

To log or not to log....that is but the question.

> 
> Ok, so what does all this mean?
> 
> It seems that there are three aspects:
> 
> 1 - jar  dependency
> 2 - runtime removal of debug statements
> 3 - library dependency
> 
> 
>    jar dependency
> --------------------------
> IE: I need to add a jar to my distro.
> 
> Possible solution: have the code use a class that is
> in the JDK already,
> and add there a method to attach a logging library
> to it.
> 
> Sample: a class that needs to log implements java.util.Observable
>          a logger attaches to it as a
> java.util.Observer
> 
> 
> 
>   runtime removal of debug statements
>
------------------------------------------------------------
> IE: I need to not include all the logging statements
> in my code
> 
> Possible solution: have the class files be
> preprocessed to remove all
> logging statements.
> 
> Sample: the class files are preprocessed by BCEL to
> remove these method
> calls
> 
> 
>   library dependency and runtime removal of debug
> statements
>
-------------------------------------------------------------
> IE: I need that logging library, and can't use mine
> 
> Possible solution + Sample: This is a bit more
> elaborate and solves in
> one go also the previous issue. Instead of adding
> the log statement, we 
> insert in the code a special comment, that a
> preprocessor then can 
> convert to use the logging library we prefer.
> 
>    //[log] "Here is my log",exp,data,etc
> 
> This needs a recompile of course. So another
> possibility would be to
> code against a common API (log4j for instance) and
> make the conversion 
> possible also without a recompile.
> 
> In this way, if I get a jar that has log4j as a
> dependency, and I don't
> want to log at all, or use my library, I could run
> it through the tool 
> and have it transparently use my logging or none at
> all.
> 
> Comments?
> 
> -- 
> Nicola Ken Barozzi                  
> [EMAIL PROTECTED]
>              - verba volant, scripta manent -
>     (discussions get forgotten, just code remains)
>
---------------------------------------------------------------------
> 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 


=====
**************************************** 
**************************************** 
** Milton Smith 
** [EMAIL PROTECTED] 
** [Yahoo! spam to follow] 
**************************************** 
****************************************

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to