logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sarna, Amit" <amit.sa...@credit-suisse.com>
Subject RE: Socket Appender
Date Fri, 10 Aug 2007 10:03:59 GMT
I apologise for continually e-mailing the list but i now also have a workin socket server for
my plain text socket appender:
 
------------------------------------------------
#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>
 
using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::net;
using namespace log4cxx::helpers;
 
int port=9245;
 
int main(int argc, const char * const argv[])
{
  PropertyConfigurator::configure("LoggerServer.cfg");
  try
  {
     LoggerPtr logger = Logger::getRootLogger();
     LOG4CXX_INFO(logger, "Listening on port " << port);
     ServerSocket serverSocket(port);
     while(true)
     {
        SocketPtr socket = serverSocket.accept();
        SocketNode* node = new SocketNode(socket, LogManager::getLoggerRepository());
        node->run();
        delete node;
    }
  }
  catch(SocketException& e)
  {
       std::cout << "SocketException";
  }
  return 0;
 
}
-----------------------------------------------------------------------------
 
 
If anyone wants the entire source code for the server + client example don't hesitate to e-mail
me. Thanks to Rayapudi for his original answer and this thread for the base for writing a
socket server:
 
http://www.mail-archive.com/log4cxx-dev@logging.apache.org/msg01100.html <http://www.mail-archive.com/log4cxx-dev@logging.apache.org/msg01100.html>
 
 


  _____  

From: Sarna, Amit [mailto:amit.sarna@credit-suisse.com] 
Sent: 10 August 2007 10:32
To: 'Log4CXX User'
Subject: RE: Socket Appender


Related question: Now i have the socket appender working with the Plain Text Socket appender.
However, the message is sent in a serialized way and i think i have to de-serialize using
a socket node. Does anybody have a good example of using socket nodes to recieve log4cxx messages
and getting them back into original format?
 
Thanks
  Amit 

  _____  

From: Sarna, Amit [mailto:amit.sarna@credit-suisse.com] 
Sent: 10 August 2007 08:57
To: 'Log4CXX User'
Subject: RE: Socket Appender


Hi Rayapudi,
  The XML appender should be fine for me if (hopefully!) it works in 0.9.7 . Thanks very much
for your help and prompt response.
 
Cheers
   Amit 

  _____  

From: Rayapudi Sandeep-mgb376 [mailto:rsandeep@motorola.com] 
Sent: 10 August 2007 08:26
To: Log4CXX User
Subject: RE: Socket Appender


Hi, 
 
I was using XML Socket appender. not a plain text. 
I seen several posts saying plain text socket appender (dont remember exact name) doesnt work.

I was using log4cxx version 0.10.0 on linux.
 
--- config file
 
log4j.rootLogger=DEBUG, myappender
 
log4j.appender.myappender=org.apache.log4j.RollingFileAppender
log4j.appender.myappender.File=../logs/abc.log
 
log4j.appender.myappender.MaxFileSize=100KB
log4j.appender.myappender.MaxBackupIndex=1
 
log4j.appender.myappender.layout=org.apache.log4j.PatternLayout
log4j.appender.myappender.layout.ConversionPattern=%d %-5p - %m%n
 
log4j.appender.SOCK=org.apache.log4j.net.XMLSocketAppender
log4j.appender.SOCK.RemoteHost=10.232.15.31
log4j.appender.SOCK.Port=9245
log4j.appender.SOCK.LocationInfo=true

 
--- example code
 
#include <log4cxx/logstring.h>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/rollingfileappender.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/logmanager.h>

 
openLogger()
{
        logger = Logger::getRootLogger();
        PropertyConfigurator::configure(LOG4CXX_FILE(pbConfigFile));
        LOG4CXX_INFO(logger, "********************* LOG OPEN *********************\n");

}
 
closeLogger()
{
        LOG4CXX_INFO(logger, "********************* LOG CLOSE *********************\n");
        LogManager::shutdown();
}
 
logMessage(strBuf)
{
    switch(logLevel)
    {
            case LOG_LEVEL_CRIT:
            case LOG_LEVEL_ERR:
                    LOG4CXX_ERROR(logger, strBuf.c_str());
                    break;
            case LOG_LEVEL_WARN:
                    LOG4CXX_WARN(logger,strBuf.c_str());
                    break;
            case LOG_LEVEL_INFO:
                    LOG4CXX_INFO(logger, strBuf.c_str());
                    break;
            case LOG_LEVEL_DBG:
            case LOG_LEVEL_TRACE:
            default:
                    LOG4CXX_DEBUG(logger,strBuf.c_str());
                    break;
    }
}
 
 
--- listening program at 10.232.15.31 at port 9245
 
#!/usr/bin/python
 
import socket
import sys
 
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
host=''
port=int("9245")
print port
s.bind((host, port))
 
s.listen(1)
conn, addr = s.accept()
print 'client is at', addr
 
while(1):
        data=conn.recv(1000)
        print data


  _____  

From: Sarna, Amit [mailto:amit.sarna@credit-suisse.com] 
Sent: Friday, August 10, 2007 12:27 PM
To: log4cxx-user@logging.apache.org
Subject: Socket Appender



Hi, 
  Does anyone have a workin example (or even does it work?) of using a socket appender (client
and server) with non-XML config in log4cxx 0.9.7 ?  I want to just send lines of log level
ERROR over a socket to another process on the same machine. I'd rather use the released 0.9.7
rather than latest development head as I can't really risk breaking any existing logging that
is in place. 

Thanks in advance 
  Amit 


==============================================================================

Please access the attached hyperlink for an important electronic communications disclaimer:




http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html

==============================================================================


==============================================================================

Please access the attached hyperlink for an important electronic communications disclaimer:




http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html

==============================================================================


==============================================================================

Please access the attached hyperlink for an important electronic communications disclaimer:




http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html

==============================================================================


==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:


http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

Mime
View raw message