Re: Logging with Jakarta log4j - How to avoid depencies?

From: Roman (anonuser_at_shaw.ca)
Date: 01/26/04


Date: Mon, 26 Jan 2004 06:32:05 GMT

Just as a quick idea, could'nt you check if the log4j Logger class exists on
start up through java reflection?
If it exists you would use the logger and if it does not there will be no
logging done.
Of course you can wrap this functionality in a class that would do the
checks upon start up.

You could also try to catch the ClassNotFound exception where ever you use
log4j and do nothing about it.

Not sure if that helps.

Roman.

"Jan van Mansum" <jvm@nospam.com> wrote in message
news:40143a91$0$318$e4fe514c@news.xs4all.nl...
> Hello group,
>
> I have just been trying out the log4j library. As far as I understand
> the idea is to keep the logging statements in your, even in the release
> build. However, obviously you wouldn't want to have to ship the log4j
> jar with your app, to avoid class definition not found exceptions. As
> a matter of fact you wouldn't want the end user to be able to turn on
> logging.
>
> I have been thinking about how to handle this. The only thing I can
> come up with so far, is just create a couple wrapper classes round the
> log4j classes and replace them with empty onces at build-time.
>
> Is this the only way to handle this problem? Has someone out there found
> a more elegant way?
>
> Thanks in advance,
> regards,
> Jan van Mansum.



Relevant Pages

  • Error loading log4j properties file
    ... I am using log4j for logging, ... HOWEVER, if I restart tomcat, everything works fine, I get no errors, ... log4j:ERROR Could not read configuration file from URL ... log4j:WARN Please initialize the log4j system properly. ...
    (comp.lang.java.programmer)
  • Logging APIs
    ... I'm familiar with Log4J, I've read about Java 1.4 Logging, used ... Commons logging to sit on top of Log4J (and read an interesting ... the Avalon logging API. ...
    (comp.lang.java.programmer)
  • log4j vs. java 1.4 logging performance
    ... but OptimizeIt (Borland's code profiler) complains that ... log4j is creating too many strings. ... This problem occurs when I turn logging ...
    (comp.lang.java.programmer)
  • Re: Current thinking on logging?
    ... I have found quite a bit on the web discussing Log4j vs JDK logging vs Commons Logging. ... Everything I read says log4j is better, but we ship a commercial app, and I really don't want to include yet another .jar file. ...
    (comp.lang.java.programmer)
  • Re: log4j vs. java 1.4 logging performance
    ... > log4j is creating too many strings. ... > logging to it's lowest levels. ... To avoid the parameter construction cost write: ...
    (comp.lang.java.programmer)