logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephane Hamel" <sha...@solvision.net>
Subject RE: AsyncAppender::close() throws ThreadException (bug?)
Date Wed, 15 Feb 2006 21:52:54 GMT
I believe I fixed the problem. I would like some feedback on the
modification I did to the code to get a normal termination of my test
application:

In the function AsyncAppender::dispatch I changed the code

if (count == 0) {
   if (pThis->closed) {
      return 0;              // original line
   }
   pThis->pending.wait();

if (count == 0) {
   if (pThis->closed) {
      pThis->thread.stop();  // modified line
   }
   pThis->pending.wait();

-Stephane

-----Original Message-----
From: Stephane Hamel [mailto:shamel@solvision.net]
Sent: February 15, 2006 4:26 PM
To: log4cxx-user@logging.apache.org
Subject: AsyncAppender::close() throws ThreadException (bug?)


Hello,

I compiled CVS Head (change list 374751, Feb 3, 2006) using the following
command:
Ant -Dcompiler=msvc -Ddebug=true build

I use Visual Studio 2005.

I tried to make the simplest program to isolate the problem. Here's the
program:

#include [...]
using namespace log4cxx;
int _tmain(int argc, _TCHAR* argv[])
{
	try
	{
		xml::DOMConfigurator::configure("LoggerConfigAsync.xml");
	}
	catch(helpers::ThreadException& e)
	{
		return 1;
	}
	return 0;
}

The LoggerConfigAsync.xml file content is:

?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="true">

	<appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
		<appender-ref ref="CONSOLE"/>
	</appender>

	<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
  		     <param name="ConversionPattern" value="%d %-5p [%t] %C{2} - %m%n"/>
		</layout>
	</appender>

	<root>
		<priority value="debug"/>
		<appender-ref ref="ASYNC"/>
	</root>
</log4j:configuration>

This application will throw an exception from within AsyncAppender::close()
method. The exception occurs when the function calls thread.join(). In
thread.join(), there's a call to apr_thread_join. Finally, in
apr_thread_join, it waits for the worker thread to terminate. After that, it
checks for thd->pool to be NULL. In my case, it is not and it returns
APR_INCOMPLETE, which is later throwned as a ThreadException.

The exception message is Thread exception: stat = 70008. (70008 =
APR_INCOMPLETE)

If, after the line:
	xml::DOMConfigurator::configure("LoggerConfigAsync.xml");

I add the following lines:
	LoggerPtr rootLogger = Logger::getRootLogger();
	LOG4CXX_INFO(rootLogger, "information message");
	LOG4CXX_DEBUG(rootLogger, "Closing AsyncAppender");
	AsyncAppenderPtr async = rootLogger->getAppender(_T("ASYNC"));
	async->close();

I will see the info and debug messages in the console, but it will crash in
the close() method anyway.

Is this "bug" occuring only w/ VS8 ?
Or is me that doesn't understand how to use this appender ?


Stéphane Hamel
SolVision
50, rue de Lauzon
Boucherville, Suite 100
(Québec) Canada, J4B 1E6
Phone: (450) 679-9542 x211



Mime
View raw message