On Tue, 20 Sep 2005 21:07:04 -0700, Albert Kennis wrote:

> I am trying to use log4cxx to send logging events to Chainsaw V2 via the 
> XMLSocketAppender channel.  Building the 0.9.8 source results in socket 
> connections being made, but not in log event data being sent.
> 
> I have located the source of this problem:  the following 2 lines are 
commented 
> out in XMLSocketAppender::renderEvent:
> 
> //USES_CONVERSION;
> 
> //os->write((void *)T2A(output.c_str()), output.length());
> 
> This results in data not being sent to the socket.
> 
> Looking through the rest of the project, I can see that anywhere the T2A 
macro 
> is used, that portion of code is commented out.  I'm have not been able to 
> locate the T2A definition, and so can not guess why its usage is being 
avoided.
> 
> If the following code is placed in XMLSocketAppender::renderEvent, the log 
> events will be transmitted (and received) successfully by Chainsaw V2:
> 
>         char * sz = (char *) malloc(output.length() + 1);
> 
>         sprintf(sz, "%S", output.c_str());
> 
>         os->write((void *)sz, output.length());
> 
>         free(sz);

Actually, this %S conversion character seems to be a proprietary extension of 
Microsoft compiler. I tested the following patch successfully on Linux:


--- log4cxx-0.9.8orig/src/xmlsocketappender.cpp 2005-10-28 21:33:19.000000000 
+0000
+++ log4cxx-0.9.8/src/xmlsocketappender.cpp     2006-03-01 18:49:01.573837000 
+0000
@@ -19,6 +19,7 @@
 #include <log4cxx/helpers/socketoutputstream.h>
 #include <log4cxx/helpers/optionconverter.h>
 #include <log4cxx/helpers/stringhelper.h>
+#include <log4cxx/helpers/transcoder.h>
 #include <log4cxx/xml/xmllayout.h>
 #include <log4cxx/level.h>
 #include <log4cxx/helpers/transform.h>
@@ -88,6 +89,18 @@
 //
 //      USES_CONVERSION;
 //      os->write((void *)T2A(sz.c_str()), sz.length());
+
+/*
+ * FIX_XML_SOCK patch
+ * convert output to a C string and perform the socket write
+ * Fred Mora, 2006/03/01 - Feel free to reuse that patch.
+ */
+
+        std::string str;
+        log4cxx::helpers::Transcoder::encode(output, str);
+        os->write(str.c_str(), str.length());
+
+/* End FIX_XML_SOCK */
 }

This encode method is part of the log4cxx helper methods so it should work 
accross architectures.

Curt, is there any drawback in using the encode method? Thread safety?

  --Fred Mora
    IBM Research



Reply via email to