This is in log4j-1.2.8.
Running in a web application, the following code is executed in this:
order
Logger log = getLogger("some log"); // not controlled by me, and so the
default configuration is loaded
// later by me
myProperties = getDynamicProperties();
PropertyConfigurator.configure(myProperties); //hoping to set the
configuration I'm interested in
Later in the application I get an error saying that: log4j:ERROR Attempted to append
to closed appender
Mucking through the code, adding LogLog messages with exceptions, I can
now see that even though AppenderAttachableImpl does indeed attempt to
call "remove" to remove the appender from the list of appenders for the
Logger, it apparently doesn't get removed.
Here's the "evidence" from my SystemErr logs:
[9/20/04 13:34:46:938] SystemErr R log4j:WARN Closing appender:
Console_Appender from stack trace.....
[9/20/04 13:34:46:938] SystemErr R java.lang.Exception: closed
appender...
[9/20/04 13:34:46:938] SystemErr R at
org.apache.log4j.WriterAppender.close(WriterAppender.java:194)
[9/20/04 13:34:46:938] SystemErr R at
org.apache.log4j.helpers.AppenderAttachableImpl.removeAllAppenders(AppenderAttachableImpl.java:133)
[9/20/04 13:34:46:938] SystemErr R at
org.apache.log4j.Category.removeAllAppenders(Category.java:881)
[9/20/04 13:34:46:938 ]SystemErr R at
org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:594)
[ SNIP ]
[9/20/04 13:34:51:250] SystemErr R log4j:ERROR Attempted to append to
closed appender named [Console_Appender], to logger:
org.kp.msgvolumechk.listener.MsgRestrictionListener with message: Checking
MessageRestrictor switch false
Here's the code in AppenderAttachableImpl:
/**
* Remove and close all previously attached appenders.
* */
public
void removeAllAppenders() {
if(appenderList != null) {
int len = appenderList.size();
for(int i = 0; i < len; i++) {
Appender a = (Appender) appenderList.elementAt(i);
LogLog.warn("closing appender: " + a.getName()); // added for
debugging by tom
a.close();
}
appenderList.removeAllElements(); // doesn't seem to work?!?
appenderList = null;
}
}
Is this a known problem, or can anyone tell if I'm doing something silly?
Note I really want to be able to call PropertyConfigurator.configure()
with a Properties object, since I want to dynamically modify the
properties before the configuration takes place. So, suggesting that I
correctly set the log4j.configuration System property is not my first
choice--but it might be the solution I have to go with.
Also, it seems that calling resetConfiguration() causes the first Logger
that was created to not work, so that doesn't seem to be a solution for me
either.
--
Tom Goetze