I have a wrapper class for log4j. Enclosed  is some code I use to test the
wrapper...

public class LoggerTest
{
        public static void main(String[] args) {
                Object[] obj = {
                        new A(),
                        new B(),
                        new C(),
                        new D()
                };
                        
                try {
                        for(int i = 0; i < obj.length; i++) {
                                TrieneLogger.getInstance().info(obj[i], "The
quick brown fox jumped over the info dog.");
                                TrieneLogger.getInstance().warn(obj[i], "The
quick brown fox jumped over the warn dog.");
                                TrieneLogger.getInstance().error(obj[i],
"The quick brown fox jumped over the error dog.");
                                TrieneLogger.getInstance().debug(obj[i],
"The quick brown fox jumped over the debug dog.");
                        }
                        throw(new Exception("log this buddy!"));
                }
                catch(Exception e) {
                        for(int i = 0; i < obj.length; i++) {
                                TrieneLogger.getInstance().info(obj[i], "The
quick brown fox jumped over the info dog.", e);
                                TrieneLogger.getInstance().warn(obj[i], "The
quick brown fox jumped over the warn dog.", e);
                                TrieneLogger.getInstance().error(obj[i],
"The quick brown fox jumped over the error dog.", e);
                                TrieneLogger.getInstance().debug(obj[i],
"The quick brown fox jumped over the debug dog.", e);
                        }
                }
        }
}

class A {}
class B {}
class C {}
class D {}

// EOF

The getInstance method calls the empty constructor...

public TrieneLogger() {
                // init instance
                instance = this;        
                
                // load properties
                BasicConfigurator.configure();
        }

If I do not call BasicConfigurator.configure() and a log4j.properties file
cannot be found, I get the following error from the first time
TrieneLogger.getInstance().info(...) is called because I haven't loaded any
configurator but I am trying to log.

log4j:ERROR No appenders could be found for category (A).
log4j:ERROR Please initialize the log4j system properly.

However, if I do call BasicConfigurator.configure() to cover myself and a
log4j.properties file is found, then there is duplicate logging to
System.out because BasicConfig is logging and the properties file defines a
customized console appender. This creates a messy confusion that I do not
want to force my team to wade through.

What I want is a way to check if PropertyConfigurator is able to find
log4j.properties and if not, then and only then call
BasicConfigurator.configure() as a backup.

Is this possible?

Andy Kriger
Triene Inc.
116 W23rd Street
Suite 500
New York, NY 10011
646.375.2364 (W)
646.298.5493 (M)



winmail.dat

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

Reply via email to