26 November 2018

Log4j config ?

A way to check if log4j is configurated at runtime.

log4j IsConfigured ::: 

    /**
     * Returns true if it appears that log4j have been previously configured. This
     * code checks to see if there are any appenders defined for log4j which is the
     * definitive way to tell if log4j is already initialized
     */
    private static boolean isConfigured() {
        Enumeration appenders = Logger.getRoot().getAllAppenders();
        if (appenders.hasMoreElements()) {
            return true;
        } else {
            Enumeration loggers = LogManager.getCurrentLoggers();
            while (loggers.hasMoreElements()) {
                Logger c = (Logger) loggers.nextElement();
                if (c.getAllAppenders().hasMoreElements())
                    return true;
            }
        }
        return false;
    }



http://wiki.apache.org/logging-log4j/UsefulCode
http://logging.apache.org/log4j/1.2/xref-test/org/apache/log4j/defaultInit/TestCase4.html
https://web.archive.org/web/20130401061324/http://dsiutils.dsi.unimi.it/
https://web.archive.org/web/20081211154329/http://dsiutils.dsi.unimi.it/docs/it/unimi/dsi/Util.html
https://web.archive.org/web/20110303190435/http://www.screaming-penguin.com/node/7622

No comments :

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.