You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2003/02/18 10:47:01 UTC

DO NOT REPLY [Bug 12671] - Log4j not working when POI jar files included in the same webapp.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12671>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12671

Log4j not working when POI jar files included in the same webapp.





------- Additional Comments From d.tonhofer@m-plify.com  2003-02-18 09:47 -------
I have had the same problem. Indeed, there is a log4j.properties file
in the jar. Thus, adding the POI jar to the CLASSPATH *MAY* change program
behaviour, even if no POI class is used at all. I'm not sure this is what
should be expected. Is there are reason for the log4j.properties file to
actually be there? POI currently does not use Commons-Logging or Log4J at
all...

Here's a test that surprises, if run with or without POI in the classpath:

package com.mplify.win2k.diskmon;

import org.apache.log4j.Appender;
import java.util.Enumeration;
import org.apache.log4j.Logger;
import org.apache.log4j.Layout;
import org.apache.log4j.Level;
import org.apache.log4j.TTCCLayout;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.LogManager;

/**********************************************************************
 * Simple test of Log4J.
 * By default, the program just writes out a description of the logging
 * hierarchy to stdout using the System.out PrintStream. If the first
 * argument to the program is 'WITH', a logger is allocated before the
 * logging hierarchy is printed to stdout.
 *
 * With 'jakarta-poi' in the classpath:
 * ====================================
 *
 * WITH Logger allocated
 * LOGGER: root
 *  Level   = DEBUG                                <-- our level for root (POI 
sets it to FATAL)
 *  Additivity = true
 *  Appender name = stdout                         <-- Jakarta-POI debugging 
appender
 *  Appender name = null                           <-- our appender for root
 * LOGGER: com.mplify.win2k.diskmon.Log4JTest.main <-- our method-specific 
logger
 *  Level   = null
 *  Additivity = true
 * LOGGER: org                                     <-- Jakarta-POI specific 
logger
 *  Level   = FATAL                                <-- ...it works at level 
FATAL
 *  Additivity = true
 *  Appender name = stdout                         <-- Jakarta-POI debugging 
appender
 *
 * WITHOUT Logger allocated
 * LOGGER: root
 *  Level   = DEBUG                                <-- our level for root (POI 
sets it to FATAL)
 *  Additivity = true
 *  Appender name = stdout                         <-- Jakarta-POI debugging 
appender
 *  Appender name = null                           <-- our appender for root
 * LOGGER: org                                     <-- Jakarta-POI specific 
logger
 *  Level   = FATAL                                <-- ...it works at level 
FATAL
 *  Additivity = true
 *  Appender name = stdout                         <-- Jakarta-POI debugging 
appender
 *
 * With no 'jakarta-poi' in the classpath:
 * =======================================
 *
 * WITH Logger allocated
 * LOGGER: root
 *  Level   = DEBUG                                 <-- our level for root
 *  Additivity = true
 *  Appender name = null                            <-- our appender for root
 * LOGGER: com.mplify.win2k.diskmon.Log4JTest.main  <-- our method-specific 
logger
 *  Level   = null
 *  Additivity = true
 *
 * 20 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 0
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 1
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 2
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 3
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 4
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 5
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 6
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 7
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 8
 * 30 [main] DEBUG com.mplify.win2k.diskmon.Log4JTest.main - This is message 9
 *
 * WITHOUT Logger allocated
 * LOGGER: root
 *  Level   = DEBUG                                 <-- our level for root
 *  Additivity = true
 *  Appender name = null                            <-- our appender for root
 *********************************************************************/

public class Log4JTest {

    private final static String PACKAGE = "com.mplify.win2k.diskmon";
    private final static String CLASS = PACKAGE + ".Log4JTest";

    /**
    * List the whole setup of Log4J's default Hierarchy
    * Except the Renderers which are not listable
    */

    public static void listSetupOfDefaultLog4JHierarchy() {
        StringBuffer buf = new StringBuffer();
        //
        // first the root element of the default hierarchy
        //
        {
            Logger root = Logger.getRootLogger();
            buf.append("LOGGER: ");
            buf.append(root.getName());
            buf.append("\n");
            buf.append(" Level   = ");
            buf.append(root.getLevel());
            buf.append("\n");
            buf.append(" Additivity = ");
            buf.append(root.getAdditivity());
            buf.append("\n");
            Enumeration appEnum = root.getAllAppenders();
            while (appEnum.hasMoreElements()) {
                Appender app = (Appender) (appEnum.nextElement());
                buf.append(" Appender name = ");
                buf.append(app.getName());
                buf.append("\n");
                // may want to check the filter and the layout of the appender
            }
        }
        //
        // then for the rest of the categories
        //
        {
            Enumeration enum = LogManager.getCurrentLoggers();
            while (enum.hasMoreElements()) {
                Logger cat = (Logger) (enum.nextElement());
                buf.append("LOGGER: ");
                buf.append(cat.getName());
                buf.append("\n");
                buf.append(" Level   = ");
                buf.append(cat.getLevel());
                buf.append("\n");
                buf.append(" Additivity = ");
                buf.append(cat.getAdditivity());
                buf.append("\n");
                Enumeration appEnum = cat.getAllAppenders();
                while (appEnum.hasMoreElements()) {
                    Appender app = (Appender) (appEnum.nextElement());
                    buf.append(" Appender name = ");
                    buf.append(app.getName());
                    buf.append("\n");
                    // may want to check the filter and the layout of the 
appender
                }
            }
        }
        System.out.println(buf.toString());
    }
    /**
     * Example main() code
     * 2) The TTCCLayout timing info is crap --- Is this also the case in UNIX?
     */

    public static void main(String[] argv) {
        Logger logger = null;
        if (argv != null && argv.length >= 1 && "WITH".equalsIgnoreCase(argv
[0])) {
            logger = Logger.getLogger(CLASS + ".main");
            System.out.println("WITH Logger allocated");
        } else {
            System.out.println("WITHOUT Logger allocated");
        }
        //
        // prepare logging
        //
        Layout layout = new TTCCLayout();
        Logger.getRoot().addAppender(new ConsoleAppender(layout, 
ConsoleAppender.SYSTEM_OUT));
        Logger.getRoot().setLevel(Level.DEBUG);
        //
        // write out how the hierarchy looks now
        //	
        listSetupOfDefaultLog4JHierarchy();
        //
        // then write some stuff
        //
        if (logger != null) {
            for (int i = 0; i < 10; i++) {
                logger.debug("This is message " + i);
            }
        }
    }
}