logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan Brown" <abr...@opstechnology.com>
Subject programmatically adding an appender to a logger...
Date Fri, 23 Apr 2004 19:44:43 GMT
I'm getting the following error when I try to add an appender to a
logger programmatically.  
 
java.lang.NullPointerException
            at org.apache.log4j.Category.addAppender(Category.java:146)
            at
test.OpsLoggerFactory.makeNewLoggerInstance(OpsLoggerFactory.java:40)
            at org.apache.log4j.Hierarchy.getLogger(Hierarchy.java:261)
            at
org.apache.log4j.LogManager.getLogger(LogManager.java:200)
            at org.apache.log4j.Logger.getLogger(Logger.java:124)
            at test.OpsLogger.getLogger(OpsLogger.java:21)
            at test.TestApp.main(TestApp.java:21)
 
 
this is the offending method...
 
public synchronized void addAppender(Appender newAppender) {
/* 142*/        if(aai == null)
/* 143*/            aai = new AppenderAttachableImpl();
/* 145*/        aai.addAppender(newAppender);
/* 146*/        repository.fireAddAppenderEvent(this, newAppender);
            }
 
so the repository field has not been set in the logger.  However the
method to set this field is protected so it must be happening as part of
a process that I have not instigated.
 
My problem in short is that I'm trying to instantiate logFiles (and
therefore loggers) dynamically.  The recommended logging solution of
logging by class name is not appropriate in my environment and I wish to
log by user instead so I've created a LoggerFactory and my
makeNewLoggerInstance() method simply creates a new RollingFileAppender
and then a new Logger and attaches to the appender to the logger.
 
 
rfa = new RollingFileAppender(new PatternLayout(), FILENAME);
rfa.setMaxFileSize("1KB");
rfa.setMaxBackupIndex(2);
rfa.setAppend(true);
rfa.activateOptions();
 
l = new OpsLogger(s);
l.addAppender(rfa);
 
however, on the last line I get the aforementioned NPE.  Any thoughts
would be appreciated
 
alan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message