Hi,
I'm sorry, it looks like I posted the wrong information; the .xml file
that I described is the reverse of that which illustrates the situation.
The correct situation is that this xml file:
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="info"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-4r [%t] %-5p %c %x -
%m%n"/>
</layout>
</appender>
<root>
<level value ="debug"/>
<appender-ref ref="STDOUT"/>
</root>
</log4j:configuration>
results in this output:
% java chapter3.BugApp3 bug0.xml
0 [main] INFO chapter3.BugApp3 - Entering application.
2 [main] INFO chapter3.BugApp3 - isDebugEnabled() returns true!
2 [main] INFO chapter3.BugApp3 - Exiting application.
If I instead set the root level to "info", then I get this:
% java chapter3.BugApp3 bug0.xml
0 [main] INFO chapter3.BugApp3 - Entering application.
1 [main] INFO chapter3.BugApp3 - Exiting application.
So, the observation is that log4j says that Debug is enabled even when
there are no appenders that log that level.
Seems that it would be more desirable to return False in that
situation.
-John
> I just did a test with 1.2.8 and got different results. Please
retest.
>
>>
>>
>> On 3/15/07, John Eisenman <[EMAIL PROTECTED]> wrote:
>> > I'm using version 1.2.14
>> >
>> > My expectation in using log4j was that a call to
logger.isXXXEnabled()
>> > would return true only in the case that a call to logger.XXX("some
>> > message") would result in the message being written to some
appender.
>> > However, it appears that the existence of an appender has no
>> bearing the
>> > Enabled call.
>> >
>> > For example, I have this simple configuration:
>> >
>> > <?xml version="1.0" encoding="UTF-8" ?>
>> > <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
>> >
>> > <log4j:configuration
xmlns:log4j='http://jakarta.apache.org/log4j/'>
>> >
>> > <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
>> > <param name="Threshold" value="debug"/>
>> > <layout class="org.apache.log4j.PatternLayout">
>> > <param name="ConversionPattern" value="%-4r [%t] %-5p %c %x -
>> %m%n"/>
>> > </layout>
>> > </appender>
>> >
>> > <root>
>> > <level value ="info"/>
>> > <appender-ref ref="STDOUT"/>
>> > </root>
>> > </log4j:configuration>
>> >
>> >
>> > Using this configuration, and this program (based on log4j's
>> examples):
>> >
>> >
>> > package chapter3;
>> >
>> > import org.apache.log4j.Logger;
>> > import org.apache.log4j.xml.DOMConfigurator;
>> >
>> > public class BugApp3 {
>> > //final static Logger logger = Logger.getLogger(BugApp3.class);
>> > final static Logger logger =
Logger.getLogger("chapter3.BugApp3");
>> >
>> > public static void main(String[] args) {
>> > DOMConfigurator.configure(args[0]);
>> >
>> > logger.info("Entering application.");
>> >
>> > //debug is not enabled
>> > logger.debug("Debug is enabled.");
>> >
>> > if (logger.isDebugEnabled()) {
>> > logger.info("isDebugEnabled() returns true!");
>> > }
>> >
>> > logger.info("Exiting application.");
>> > }
>> > }
>> >
>> > I see the following output:
>> >
>> > % java chapter3.BugApp3 bug0.xml
>> > 0 [main] INFO chapter3.BugApp3 - Entering application.
>> > 2 [main] INFO chapter3.BugApp3 - isDebugEnabled() returns
true!
>> > 3 [main] INFO chapter3.BugApp3 - Exiting application.
>> >
>> > However, if I set the root level to "debug" instead, then I get
this
>> > output instead:
>> >
>> > % java chapter3.BugApp3 bug0.xml
>> > 1 [main] INFO chapter3.BugApp3 - Entering application.
>> > 3 [main] INFO chapter3.BugApp3 - Exiting application.
>> >
>> > Since the goal of an isXXXEnabled() statement is to avoid doing
>> > unnecessary work in the case where it will not result in actual
debug
>> > output, it seems unfortunate that it does not take into account the
>> > existence of an appender.
>> >
>> > Is this behavior intentional?
>> >
>> > -John
>> >
>> >
>> >
>> >
>> >
>> >
---------------------------------------------------------------------
>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>> > For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>>
>>
>> --
>> James Stauffer http://www.geocities.com/stauffer_james/
>> Are you good? Take the test at http://www.livingwaters.com/good/
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]