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 Tom Caulkins <To...@sas.com> on 2002/08/08 19:10:25 UTC
Same-name logger configs confuse DOMConfigurator
Just passing along something I discovered. It's probably not officially a bug, since it results from what could be considered a user error. However, the log4j support team may be interested, since it might be possible to warn the user of what's happening. Also, the behavior, as best I can tell, is different between the DOMConfigurator and the PropertyConfigurator, when presented with the same configurations. So, the details...
In my sample program, I create 3 different loggers and send one message to each logger:
import org.apache.log4j.Logger;
import org.apache.log4j.BasicConfigurator;
public class MyApp {
static Logger logger1 = Logger.getLogger("category1");
static Logger logger2 = Logger.getLogger("category2");
static Logger logger3 = Logger.getLogger("other");
public static void main(String[] args) {
logger1.debug("This is a category1 message");
logger2.debug("This is a category2 message");
logger3.debug("This is an other message");
}
}
My configuration files specify these relationships between loggers and outputs:
root - Console
category1 - Console
category2 - Console
category2 - File ( second specifier for category2 )
If I am using the PropertyConfigurator, the result is as if the first specification for category2 didn't exist ( the second one over-rides it ). The output from "category1" and "other" go to the Console, while "category2" goes to the File. However, if I am using the DOMConfigurator, "category2" output still goes to the File, but the output to the Console is:
log4j:ERROR Attempted to append to closed appender named [A1].
log4j:ERROR Attempted to append to closed appender named [A1].
This represents the output from the "category1" and "other" loggers, which has been crippled by the configuration of the "category2" logger. Again, I expect that twice configuring a logger is a user error ( is this documented anywhere??? ) but it would still be nice, if possible, to let the user know the root cause of the messages they are seeing. Hopefully that will be possible. I will attach the two configurations ( which I specify with the -Dlog4j.configuration= option on the java command line ) at the bottom of this email.
Thanks,
Tom
------------------------------------------
Tom Caulkins
Senior Systems Developer
Platform Services - Business Intelligence Platform
SAS Institute Inc.
Tom.Caulkins@sas.com
The .properties file:
log4j.rootLogger=debug, A1
log4j.logger.category1=debug, A1
log4j.additivity.category1=false
log4j.logger.category2=debug, A1
log4j.additivity.category2=false
log4j.logger.category2=debug, F2
log4j.additivity.category2=false
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%5p [%t] - %m%n
log4j.appender.F2=org.apache.log4j.RollingFileAppender
log4j.appender.F2.File=example.log
log4j.appender.F2.MaxFileSize=10MB
log4j.appender.F2.MaxBackupIndex=1
log4j.appender.F2.layout=org.apache.log4j.PatternLayout
log4j.appender.F2.layout.ConversionPattern=%p %t %c - %m%n
The .xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender
class="org.apache.log4j.ConsoleAppender"
name="A1">
<layout
class="org.apache.log4j.PatternLayout">
<param
name="ConversionPattern"
value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<appender
class="org.apache.log4j.FileAppender"
name="F2">
<param
name="file"
value="example.log"/>
<param
name="immediateFlush"
value="true"/>
<param
name="append"
value="false"/>
<layout
class="org.apache.log4j.PatternLayout">
<param
name="ConversionPattern"
value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<category
additivity="false"
name="category1">
<priority
value="DEBUG"/>
<appender-ref
ref="A1"/>
</category>
<category
additivity="false"
name="category2">
<priority
value="DEBUG"/>
<appender-ref
ref="A1"/>
</category>
<category
additivity="false"
name="category2">
<priority
value="DEBUG"/>
<appender-ref
ref="F2"/>
</category>
<root>
<priority
value="DEBUG"/>
<appender-ref
ref="A1"/>
</root>
</log4j:configuration>
p.s. Please excuse my mix of 1.1 and 1.2 syntax - I'm fairly confident that it's not a factor in the issue I'm presenting.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>