Hello Andreas,

My sample is an application with a SocketAppender which should send logging 
events (client) to another application with a SocketNode (server) which should 
log these events. The problem is, when the server receives an event an trys to 
get the logger name from this event the application crashs. Here the call stack:

msvcp71d.dll!std::basic_string<unsigned short,std::char_traits<unsigned 
short>,std::allocator<unsigned short> >::size()  Line 1109 + 0x3        C++
msvcp71d.dll!std::basic_string<unsigned short,std::char_traits<unsigned 
short>,std::allocator<unsigned short> >::assign(const 
std::basic_string<unsigned short,std::char_traits<unsigned 
short>,std::allocator<unsigned short> > & _Right={...}, unsigned int _Roff=0, 
unsigned int _Count=4294967295)  Line 591 + 0x8  C++
msvcp71d.dll!std::basic_string<unsigned short,std::char_traits<unsigned 
short>,std::allocator<unsigned short> >::basic_string<unsigned 
short,std::char_traits<unsigned short>,std::allocator<unsigned short> >(const 
std::basic_string<unsigned short,std::char_traits<unsigned 
short>,std::allocator<unsigned short> > & _Right={...})  Line 326       C++
log4cxxD.dll!log4cxx::Logger::getName()  Line 261 + 0x31        C++
log4cxxD.dll!log4cxx::spi::LoggingEvent::getLoggerName()  Line 84 + 0x16        
C++
log4cxxD.dll!log4cxx::net::SocketNode::run()  Line 55 + 0x20    C++
log4cxx_simplesocketserver.exe!runSocket(void * __formal=0x009e42a8, void * 
data=0x009db668)  Line 25 + 0xc     C++
log4cxxD.dll!dummy_worker(void * opaque=0x009e42a8)  Line 79 + 0x13     C
msvcr71d.dll!_threadstartex(void * ptd=0x009dbc18)  Line 241 + 0xd      C
kernel32.dll!7c80b683()

I think this is because in the method event->read(is); is everything commented 
out and so the logger name is not set. Also I think this is commented out 
because in the SocketInputStream the read method is not complete.
So the subject of my mail is not correct. I better would call it "Which effort 
would it be to make LoggingEvent and SocketInputStream run?"

Here the client code and property file:
=====================================================================================
#include <log4cxx/logger.h>
#include <log4cxx/net/socketappender.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/logmanager.h>
#include <windows.h>

using namespace log4cxx;
using namespace log4cxx::net;

int main(int argc, const char * const argv[])
{
   PropertyConfigurator::configure(File("log4cxx.properties"));
   LoggerPtr logger = Logger::getLogger(LOG4CXX_STR("SimpleSocketLogger"));
   int counter = 0;
   LogString message = LOG4CXX_STR("This is a test");
   while (counter < 100)
   {
      LOG4CXX_INFO(logger, message)
      ++counter;
      Sleep(500);
   }
   return 0;
}
=====================================================================================
log4j.debug=true
log4j.rootLogger=DEBUG
log4j.logger.SimpleSocketLogger=DEBUG, socketAppender
log4j.appender.socketAppender=org.apache.log4j.net.SocketAppender
log4j.appender.socketAppender.RemoteHost=localhost
log4j.appender.socketAppender.Port=1234
=====================================================================================
Here the server code and property file:
=====================================================================================
#include <log4cxx/portability.h>
#include <log4cxx/logger.h>
#include <log4cxx/helpers/serversocket.h>
#include <log4cxx/helpers/socket.h>
#include <log4cxx/net/socketnode.h>
#include <log4cxx/xml/domconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/thread.h>
#include <log4cxx/logmanager.h>
#include <log4cxx/level.h>
#include <log4cxx/helpers/stringhelper.h>
#include <iostream>
#include <log4cxx/stream.h>

using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::net;
using namespace log4cxx::helpers;

int port = 1234;

void* LOG4CXX_THREAD_FUNC runSocket(log4cxx_thread_t* /* thread */, void* data)
{
   SocketNode* node = (SocketNode*) data;
   node->run();
   delete node;
   return 0;
}

int main(int argc, const char * const argv[])
{
   PropertyConfigurator::configure(File("log4cxx.properties"));
   try
   {
      LoggerPtr logger = Logger::getLogger(LOG4CXX_STR("SimpleSocketLogger"));
      log4cxx::logstream logstream(logger, Level::INFO);
      logstream << "Listening on port " << port;
      logstream.flush();
      ServerSocket serverSocket(port);
      while(true)
      {
         logstream << "Waiting to accept a new client.";
         logstream.flush();
         SocketPtr socket = serverSocket.accept();
         logstream << "Connected to client at " << 
socket->getInetAddress()->toString();
         logstream << "Starting new socket node.";
         logstream.flush();
         Thread * thread = new Thread();
         SocketNode* node = new SocketNode(socket, 
LogManager::getLoggerRepository());
         thread->run(runSocket, node);
      }
   }
   catch(SocketException& e)
   {
      std::cout << "SocketException: " << e.what() << std::endl;
   }

   return 0;
}
=====================================================================================
log4j.debug=true
log4j.rootLogger=DEBUG
log4j.logger.SimpleSocketLogger=DEBUG, consoleAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=\%d{EE MMM dd 
HH:mm:ss.SS yyyy}ÿ\%m\%n
=====================================================================================

I begin to believe that I do something wrong ... I cannot believe that I'm the 
first one how tries this. But I found no mail in the dev or user list which is 
about this.

Best Regards,

Christian

-----Ursprüngliche Nachricht-----
Hi Christian,

thats why I asked ;-)
The socketappender uses the socketOUTPUTstream to write data, and this class
should work.
Can you provide a minimal code sample of what you are trying to do and
which shows the issue?

Regards,

        Andreas

Reply via email to