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 Mark Masterson <ma...@compuserve.com> on 2001/01/23 10:59:46 UTC

DOMConfigurator.configureAndWatch w/multiple async appenders

Greetings,

I'm struggling with the "configureAndWatch" method.  In our project, we want
to do all logging asynch.  Additionally, we want to direct different
severity levels to different targets (appenders), and we want to be able to
use the Category hierarchy to vary the level of logging output.  I've got
all this working great, with static configuration.  My problem is, when I
try to use the "configureAndWatch" method (as opposed to just "configure",
eh?), something's going wrong.  On the surface, it seems as if only the
appenders that are attached to root are being re-initialized.  Here's the
XML config file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration SYSTEM "log4j.dtd">

<configuration configDebug="true">

	<appender name="ASYNC_ROOT" class="org.apache.log4j.AsyncAppender">
	        <appender-ref ref="STDOUT"/>
                <appender-ref ref="ERROR_LOG"/>
	</appender>

        <appender name="ASYNC_DEBUG" class="org.apache.log4j.AsyncAppender">
	        <appender-ref ref="DEBUG_LOG"/>
	</appender>

	<appender name="ERROR_LOG" class="org.apache.log4j.FileAppender">
		<param name="File" value="error.log"/>
                <param name="Threshold" value="ERROR"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern"
                            value="%d,%p,[%t],[%c],%m%n"/>
		</layout>
	</appender>

        <appender name="DEBUG_LOG" class="org.apache.log4j.FileAppender">
		<param name="File" value="debug.log"/>
                <param name="Threshold" value="DEBUG"/>
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern"
                            value="%d,%p,[%t],[%c],%x,%m%n"/>
		</layout>
	</appender>

        <appender name="STDOUT" class="org.apache.log4j.FileAppender">
           		<param name="File" value="System.out" />
                        <param name="Threshold" value="ERROR"/>
           		<layout class="org.apache.log4j.PatternLayout">
             		<param name="ConversionPattern"
value="%d,%p,[%t],[%c],%x,%m%n"/>
           		</layout>
	</appender>

	<category name="trace_test.TraceTestFrame.methodName" additivity="true">
                <priority value="debug"/>
                <appender-ref ref="ASYNC_DEBUG"/>
        </category>

        <root>
		<priority value="error"/>
                <appender-ref ref="ASYNC_ROOT"/>
	</root>
</configuration>

In my code, I'm using Category objects per class, plus one extra Category in
a specific method.  In the config above, I have things set up to limit debug
output to this one method, and that works fine.  If I change the category
definition in the config file, changing it from the FQN for the method, for
example, to just the package name (i.e. from
"trace_test.TraceTestFrame.methodName" to "trace_test"), and re-run the app,
I get debug output from all of my Category objects.  Now, if I use
"configureAndWatch" and change the lines as described above, this doesn't
work.  If I start with the more restrictive variant (method name), and
change to the looser one (package name), I expect to see all of the debug
output being logged after the changed config file is re-loaded.  But this
doesn't happen.

Interestingly, with "configDebug=true", I see the following statements on
the console after the re-initialization:
log4j: Finalizing appender named [STDOUT].
log4j: Finalizing appender named [ERROR_LOG].

Note that these are the 2 appenders that are attached to the asynch appender
that is attached to root.  There is no mention of "finalizing" the DEBUG_LOG
appender that is attached to the other asynch appender that is attached to
my category.

Am I doing something wrong?  Is there in error in my config file?  Or have I
stumbled over a bug?

Thanks in advance.
--Mark