I'm using log4j in what is effectively a library -- code that is
called from lots of places (different applications and jvms), some of
which I don't write.  I am using log4j in the library, and
applications that I write properly configure log4j.  However, I would
like the library to be usable from code that is not log4j aware, and
in particular not have the "No appenders could be found ... " message
printed.

I would like to be able to either:

1) Turn off the printing of the no appender warning message for a
particular category.  This could easily be implemented by a method in
Category that sets emittedNoAppenderWarning to true.

2) (Possibly a better solution) Disable all logging from the library
by default, but enable logging if log4j is configured.  This can, I
believe, be accomplished by calling BasicConfigurator.disableAll() in
a static initialization block in each library class.  However, when
the log4j system is configured, BasicConfigurator.overrideAsNeeded()
must be called or the log4j.disableOverride property must be set.  I
would prefer to be able to only disable the Categories used in the
library.

It would be easier to solve this problem if one could determine if
any configuration has been done, that is, if there are any Appenders
attached to any Category.  It seems like this would be very easy to
keep track of by simply setting a boolean in the Hierarchy.  Then, I
would only call disableAll() in my libraries if no configuration had
been done -- if configuration had been done, I would assume I am
running in a log4j aware application, and that it will do appropriate
configuration.

I can think of several ways to solve this problem by extending
Category or otherwise writing new code, but it seems like a common
enough situation that there should be a way to do what I want with the
standard distribution.  What solutions am I missing?

Thanks,

        Brendan



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

Reply via email to