Yoav, Thanks for the reply. I had come to a similar conclusion, but hoped I was wrong. IMHO, both options are undesirable because they require manual intervention and knowledge of log4j. As a component developer, I want to remove any items not directly related to the main function of the component. Logging is important, but the user should not need to know or care about logging in order to use the component. Small learning curve and the ability to "drop" in a component with little or no fuss is essential to me. For now I am using a property flag that turns on and off component configuration. Which works, but I still need an automated/programmatic approach.
A method added to Logger, which indicates whether or not the repository has been configured would be ideal. Something like: public class MyClass { private Logger log = Logger.getLogger (...); public MyClass () { if (!log.isRepositoryConfigured()) // If it is not configured DOMConfigurator.configure (...); // then configure it. } } I have also, run into this issue with non-component classes (i.e. utility class libs). Sometimes I create quick and dirty Proof of Concepts/Demos, that use existing classes. The existing classes use log4j, but the new POC/Demo does not. What is involved to add a method to verify if log4j has been initialized? Thanks, Jim -----Original Message----- From: Shapira, Yoav [mailto:[EMAIL PROTECTED]] Sent: Monday, January 27, 2003 6:10 AM To: Log4J Users List; [EMAIL PROTECTED] Subject: RE: How to verify a Configurator is configured Howdy, A "Configurator" is never configured. A logging repository is configured. One way I've used for testing, although I don't think this is the type of thing that should be tested at all (keep reading for why), is as follows: Logger rootLogger = Logger.getRootLogger(); Enumeration appenders = rootLogger.getAllAppenders(); if((appenders == null) || (appenders instanceof NullEnumeration)) { // Log4j hasn't been configured, configure it... } I don't think this should be tested because: as a component author, you state in your installation document/readme/manual that you require log4j. You document how log4j can be configured for your use. This is a required step for someone using your component. If they don't do it, they get the log4j not configured warning that you mention and logging doesn't work. If you don't belong in the above bin, you can be in another one: your documentation will state that the log4j configuration file must reside in a specific location (e.g. with your component's jar file). Your component will then always configure itself from this file. I believe either one of the above is better than trying to detect if you've been configured, and if not using some minimum (in this case BasicConfigurator) settings. Yoav Shapira Millennium ChemInformatics >-----Original Message----- >From: Jim Mack [mailto:[EMAIL PROTECTED]] >Sent: Saturday, January 25, 2003 11:39 PM >To: [EMAIL PROTECTED] >Subject: How to verify a Configurator is configured > >Hello, > I am developing some components and I want them to use a Configurator >defined outside the component or BasicConfigurator if one is not defined. >If >a Configurator is not defined, several messages are written to standard out >i.e. "log4j:WARN Please initialize the log4j system properly." This message >seems to suggest that some object knows the system is not correctly setup, >but I could not find any methods to get that state. Did I miss something? >How can I verify that a Configurator has been configured? > >Thanks, >Jim > > >-- >To unsubscribe, e-mail: <mailto:log4j-user- >[EMAIL PROTECTED]> >For additional commands, e-mail: <mailto:log4j-user- >[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>