You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by "Sarna, Amit" <am...@credit-suisse.com> on 2007/08/10 08:56:53 UTC
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
==============================================================================
RE: Socket Appender
Posted by Rayapudi Sandeep-mgb376 <rs...@motorola.com>.
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
========================================================================
======