I am attempting to log message via log4cplus::SocketAppender. These messages are serialized using google protobuf.
I have no problem sending logs with small size. However, if I attempt to log messages with character length greater than 8000, I get following error message:
log4cplus:ERROR SocketBuffer::appendString()- Attempt to write beyond end of buffer
My current workaround is breaking these buffers into smaller chunks before sending it across the network.
Here is a snippet of my property file (named test.properties):
log4cplus.rootLogger=TRACE
log4cplus.logger.loglogger = TRACE,SocketAppender
log4cplus.appender.SocketAppender = log4cplus::SocketAppender
log4cplus.appender.SocketAppender.host=127.0.0.1
log4cplus.appender.SocketAppender.port = 5555
log4cplus.appender.SocketAppender.serverName = simpleserver
Here is a snippet of my sender code:
int main()
{
log4cplus::initialize();
LogLog::getLogLog()->setInternalDebugging(true);
{
ConfigureAndWatchThread* configureThread = new ConfigureAndWatchThread(LOG4CPLUS_TEXT("test.properties"), 1000);
root = Logger::getRoot();
loglogger = Logger::getInstance("loglogger");
loglogger.setLogLevel(ALL_LOG_LEVEL);
unsigned char Mybuffer[10000];
//populating and serializing code for Mybuffer
LOG4CPLUS_INFO(loglogger,Mybuffer);
}
return 0;
}
Question:
- Is it something that I am missing in the property file which is causing this issue?
- Is there a way to increase this socket buffer size so that I can send buffers with more than 8000 characters?
If your
MyBufferis binary data then you are using log4cplus wrong. It is meant to log text strings, not binary data.Also, there is a limit to the length of a buffer to
8*1024bytes. Seesocketappender.h.