jk> There are ways to figure out if Log4j has been configured in
jk> 1.2.x.  Try this...

jk> http://wiki.apache.org/logging-log4j/Log4JProjectPages/UsefulCode

I'm a little confused by this cite.  I presume you're talking about
the Log4jConfigurator example.  That looks like a fairly vanilla
example of a singleton class to keep yourself from double-dipping
log4j.  That does nothing to tell you if it's already been configured
by somebody else, or am I misreading it?

We do this around here:

    /**
     * log4j has a wacky default if it doesn't get any configuration help from the 
environment.
     * It turns on DEBUG at the RootLogger level.  So, everything wrapped in 
isDebugEnabled will
     * be done even though it is written to nowhere.  Grrr.  This method looks for 
that condition.
     * If all loggers (1) have no appenders, and (2) are at DEBUG level, then fix 
things up by
     * setting the RootLogger at the ERROR level (which will cascade down).
     * @return whether or not corrective action was taken.
     */
    protected static boolean checkForCrazyLog4jDefault()
    {
        org.apache.log4j.Logger rl = org.apache.log4j.Logger.getRootLogger();
        if (!loggerIsThatCrazyWay(rl)) return false;
        Enumeration allLoggers = LogManager.getCurrentLoggers();
        while (allLoggers.hasMoreElements())
        {
            org.apache.log4j.Logger lgr = 
(org.apache.log4j.Logger)allLoggers.nextElement();
            if (! loggerIsThatCrazyWay(lgr)) return false;
        }
        // OK, I guess it *is* that crazy way... change to a different, slightly less 
crazy way
        rl.setLevel(Level.ERROR);
        return true;
    }
    private static boolean loggerIsThatCrazyWay(org.apache.log4j.Logger lgr)
    {
        Enumeration appenders = lgr.getAllAppenders();
        if (appenders.hasMoreElements()) return false;
        Level lvl = lgr.getEffectiveLevel();
        if (lvl != null)
        {
            if (! lvl.equals(Level.DEBUG)) return false;
        }
        return true;
    }


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

Reply via email to