You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Jason Novotny <jd...@lbl.gov> on 2003/05/06 16:25:13 UTC

log4j throws exception for some classes and not others

I'm wrapping Log4J in my own logger class and configuring the 
log4j.properties file like so:

public SportletLog {

static {
        URL propsURL = 
SportletLog.class.getResource("/gridsphere/log4j.properties");
        PropertyConfigurator.configure(propsURL);
    }


/**
     * Return an instance of the PortletLog for a particular class
     *
     * @return the PortletLog
     */
    public static synchronized PortletLog getInstance(Class clazz) {
        SportletLog log = (SportletLog) logMap.get(clazz);
        if (log != null) return log;
        log = new SportletLog(clazz);
        logMap.put(clazz, new SportletLog(clazz));
        return log;
    }
   
    public void debug(String text) {
        logger.log(thisClassName, Level.DEBUG, text, null);
    }

    ...

   }


    Now this works fine in general-- the Jar file containing my logger 
is deployed to the Tomcat servlet conatiner in shared/lib so that it is 
accessible to other web applications. However, it seems that when a 
non-core class is doing any logging.. e.g  specific webapp classes, then 
I often get the error below:

2003-05-06 16:06:48 ApplicationDispatcher[/gridsphere] Servlet.service() 
for servlet LoginPortlet threw exception
java.lang.NullPointerException
        at java.io.Writer.write(Writer.java:124)
        at org.apache.log4j.helpers.QuietWriter.write(QuietWriter.java:39)
        at 
org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:299)
        at org.apache.log4j.WriterAppender.append(WriterAppender.java:150)
        at 
org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)
        at 
org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)
        at org.apache.log4j.Category.callAppenders(Category.java:187)
        at org.apache.log4j.Category.forcedLog(Category.java:372)
        at org.apache.log4j.Category.log(Category.java:864)
        at 
org.gridlab.gridsphere.portlet.impl.SportletLog.error(SportletLog.java:146)

I'm not entirely sure what is going on here-- does anyone have any 
ideas? Really I'm just trying to configure the log4j.properties file as 
easy as possible. Ideally, I would like each webapp to have a separate 
log4j.properties file that is accessible from WEB-INF or something 
rather than putting it in the Jar file and using the 
PropertyConfigurator the way I do above. Any insight is greatly appreciated.

    Thanks, Jason



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org