Hi,

Does anybody know how to test to see if Log4J has been configured or not.
I want to configure it with DEFAULTS if it is not already configured.
Here is my code snippet:

 static Category log = Category.getInstance("myclass");

Basic Startup:

 try {
            File logConfigFile = getConfigFile("log_config.xml");
            PropertyConfigurator.configure(logConfigFile.toString());
 } catch(FileNotFoundException e) {
            // if there is a problem, resort to basic logging
            BasicConfigurator.configure();
            log.warn("couldnt find log config file, using basic settings");
 }



I am trying to find out if Log4J has been configured.  To do this, I tried
the following and keep getting an Enumerator with no elements.
I called the setConfigurator() method without running the basic startup and
got the same result.

    private static void setConfigurator(Category log) {
        Enumeration enum = log.getAllAppenders();
        String foo = "";

        if (!enum.hasMoreElements()) {
            ConsoleAppender ca = new ConsoleAppender(new SimpleLayout());
            PropertyConfigurator.configure(ca);
            log.debug("PropertyConfigurator using DEFAULT Setting");
        }
    }



Thanks!





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

Reply via email to