[prev in list] [next in list] [prev in thread] [next in thread]
List: log4cxx-dev
Subject: svn commit: r1720193 - in /incubator/log4cxx/trunk/src/main: cpp/objectoutputstream.cpp cpp/socketap
From: tschoening () apache ! org
Date: 2015-12-15 16:53:55
Message-ID: 20151215165355.25EF43A0702 () svn01-us-west ! apache ! org
[Download RAW message or body]
Author: tschoening
Date: Tue Dec 15 16:53:54 2015
New Revision: 1720193
URL: http://svn.apache.org/viewvc?rev=1720193&view=rev
Log:
LOGCXX-461: hopefully improved readability
Modified:
incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp
incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp
incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h
incubator/log4cxx/trunk/src/main/include/log4cxx/net/socketappender.h
Modified: incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp?rev=1720193&r1=1720192&r2=1720193&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp (original)
+++ incubator/log4cxx/trunk/src/main/cpp/objectoutputstream.cpp Tue Dec 15 16:53:54 \
2015 @@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -31,164 +31,197 @@ using namespace log4cxx::helpers;
IMPLEMENT_LOG4CXX_OBJECT(ObjectOutputStream)
ObjectOutputStream::ObjectOutputStream(OutputStreamPtr outputStream, Pool& p)
- : os(outputStream) ,
- utf8Encoder(CharsetEncoder::getUTF8Encoder()),
- objectHandle(0x7E0000),
- classDescriptions(new ClassDescriptionMap())
+ : os(outputStream),
+ utf8Encoder(CharsetEncoder::getUTF8Encoder()),
+ objectHandle(0x7E0000),
+ classDescriptions(new ClassDescriptionMap())
{
- char start[] = { static_cast<char>(0xAC), static_cast<char>(0xED), 0x00, 0x05 };
- ByteBuffer buf(start, sizeof(start));
- os->write(buf, p);
+ char start[] = { static_cast<char>(0xAC), static_cast<char>(0xED), 0x00, 0x05 };
+ ByteBuffer buf(start, sizeof(start));
+ os->write(buf, p);
}
-ObjectOutputStream::~ObjectOutputStream() {
- delete classDescriptions;
+ObjectOutputStream::~ObjectOutputStream()
+{
+ delete classDescriptions;
}
-void ObjectOutputStream::close(Pool& p) {
- os->close(p);
+void ObjectOutputStream::close(Pool& p)
+{
+ os->close(p);
}
-void ObjectOutputStream::flush(Pool& p) {
- os->flush(p);
+void ObjectOutputStream::flush(Pool& p)
+{
+ os->flush(p);
}
-void ObjectOutputStream::writeObject(const LogString& val, Pool& p) {
- objectHandle++;
- writeByte(TC_STRING, p);
- char bytes[2];
+void ObjectOutputStream::writeObject(const LogString& val, Pool& p)
+{
+ objectHandle++;
+ writeByte(TC_STRING, p);
+ char bytes[2];
#if LOG4CXX_LOGCHAR_IS_UTF8
- size_t len = val.size();
- ByteBuffer dataBuf(const_cast<char*>(val.data()), val.size());
+ size_t len = val.size();
+ ByteBuffer dataBuf(const_cast<char*>(val.data()), val.size());
#else
- size_t maxSize = 6 * val.size();
- char* data = p.pstralloc(maxSize);
- ByteBuffer dataBuf(data, maxSize);
- LogString::const_iterator iter(val.begin());
- utf8Encoder->encode(val, iter, dataBuf);
- dataBuf.flip();
- size_t len = dataBuf.limit();
+ size_t maxSize = 6 * val.size();
+ char* data = p.pstralloc(maxSize);
+ ByteBuffer dataBuf(data, maxSize);
+ LogString::const_iterator iter(val.begin());
+ utf8Encoder->encode(val, iter, dataBuf);
+ dataBuf.flip();
+ size_t len = dataBuf.limit();
#endif
- bytes[1] = (char) (len & 0xFF);
- bytes[0] = (char) ((len >> 8) & 0xFF);
- ByteBuffer lenBuf(bytes, sizeof(bytes));
- os->write(lenBuf, p);
- os->write(dataBuf, p);
-}
-
-
-void ObjectOutputStream::writeObject(const MDC::Map& val, Pool& p) {
- //
- // TC_OBJECT and the classDesc for java.util.Hashtable
- //
- char prolog[] = {
- 0x72, 0x00, 0x13, 0x6A, 0x61, 0x76, 0x61,
- 0x2E, 0x75, 0x74, 0x69, 0x6C, 0x2E, 0x48, 0x61,
- 0x73, 0x68, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x13,
- static_cast<char>(0xBB), 0x0F, 0x25, 0x21, 0x4A, static_cast<char>(0xE4), \
static_cast<char>(0xB8), 0x03,
- 0x00, 0x02, 0x46, 0x00, 0x0A, 0x6C, 0x6F, 0x61,
- 0x64, 0x46, 0x61, 0x63, 0x74, 0x6F, 0x72, 0x49,
- 0x00, 0x09, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68,
- 0x6F, 0x6C, 0x64, 0x78, 0x70 };
- writeProlog("java.util.Hashtable", 1, prolog, sizeof(prolog), p);
- //
- // loadFactor = 0.75, threshold = 5, blockdata start, buckets.size = 7
- char data[] = { 0x3F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
- TC_BLOCKDATA, 0x08, 0x00, 0x00, 0x00, 0x07 };
- ByteBuffer dataBuf(data, sizeof(data));
- os->write(dataBuf, p);
- char size[4];
- size_t sz = val.size();
- size[3] = (char) (sz & 0xFF);
- size[2] = (char) ((sz >> 8) & 0xFF);
- size[1] = (char) ((sz >> 16) & 0xFF);
- size[0] = (char) ((sz >> 24) & 0xFF);
- ByteBuffer sizeBuf(size, sizeof(size));
- os->write(sizeBuf, p);
- for(MDC::Map::const_iterator iter = val.begin();
- iter != val.end();
- iter++) {
- writeObject(iter->first, p);
- writeObject(iter->second, p);
- }
- writeByte(TC_ENDBLOCKDATA, p);
-}
-
-void ObjectOutputStream::writeUTFString(const std::string& val, Pool& p) {
- char bytes[3];
- size_t len = val.size();
- ByteBuffer dataBuf(const_cast<char*>(val.data()), val.size());
- objectHandle++;
- bytes[0] = 0x74;
- bytes[1] = (char) ((len >> 8) & 0xFF);
- bytes[2] = (char) (len & 0xFF);
- ByteBuffer lenBuf(bytes, sizeof(bytes));
- os->write(lenBuf, p);
- os->write(dataBuf, p);
-}
-
-
-
-void ObjectOutputStream::writeByte(char val, Pool& p) {
- ByteBuffer buf(&val, 1);
- os->write(buf, p);
-}
-
-void ObjectOutputStream::writeInt(int val, Pool& p) {
- char bytes[4];
- bytes[3] = (char) (val & 0xFF);
- bytes[2] = (char) ((val >> 8) & 0xFF);
- bytes[1] = (char) ((val >> 16) & 0xFF);
- bytes[0] = (char) ((val >> 24) & 0xFF);
- ByteBuffer buf(bytes, sizeof(bytes));
- os->write(buf, p);
-}
-
-void ObjectOutputStream::writeLong(log4cxx_time_t val, Pool& p) {
- char bytes[8];
- bytes[7] = (char) (val & 0xFF);
- bytes[6] = (char) ((val >> 8) & 0xFF);
- bytes[5] = (char) ((val >> 16) & 0xFF);
- bytes[4] = (char) ((val >> 24) & 0xFF);
- bytes[3] = (char) ((val >> 32) & 0xFF);
- bytes[2] = (char) ((val >> 40) & 0xFF);
- bytes[1] = (char) ((val >> 48) & 0xFF);
- bytes[0] = (char) ((val >> 56) & 0xFF);
- ByteBuffer buf(bytes, sizeof(bytes));
- os->write(buf, p);
-}
-
-void ObjectOutputStream::writeBytes(const char* bytes, size_t len, Pool& p) {
- ByteBuffer buf(const_cast<char*>(bytes), len);
- os->write(buf, p);
-}
-
-void ObjectOutputStream::writeNull(Pool& p) {
- writeByte(TC_NULL, p);
-}
-
-void ObjectOutputStream::writeProlog(const char* className,
- int classDescIncrement,
- char* classDesc,
- size_t len,
- Pool& p) {
- ClassDescriptionMap::const_iterator match = classDescriptions->find(className);
- if (match != classDescriptions->end()) {
- char bytes[6];
- bytes[0] = TC_OBJECT;
- bytes[1] = TC_REFERENCE;
- bytes[2] = (char) ((match->second >> 24) & 0xFF);
- bytes[3] = (char) ((match->second >> 16) & 0xFF);
- bytes[4] = (char) ((match->second >> 8) & 0xFF);
- bytes[5] = (char) (match->second & 0xFF);
- ByteBuffer buf(bytes, sizeof(bytes));
- os->write(buf, p);
- objectHandle++;
- } else {
- classDescriptions->insert(ClassDescriptionMap::value_type(className, \
objectHandle));
- writeByte(TC_OBJECT, p);
- ByteBuffer buf(classDesc, len);
- os->write(buf, p);
- objectHandle += (classDescIncrement + 1);
- }
-}
+ bytes[1] = (char) (len & 0xFF);
+ bytes[0] = (char) ((len >> 8) & 0xFF);
+ ByteBuffer lenBuf(bytes, sizeof(bytes));
+
+ os->write(lenBuf, p);
+ os->write(dataBuf, p);
+}
+
+
+void ObjectOutputStream::writeObject(const MDC::Map& val, Pool& p)
+{
+ //
+ // TC_OBJECT and the classDesc for java.util.Hashtable
+ //
+ char prolog[] = {
+ 0x72, 0x00, 0x13, 0x6A, 0x61, 0x76, 0x61,
+ 0x2E, 0x75, 0x74, 0x69, 0x6C, 0x2E, 0x48, 0x61,
+ 0x73, 0x68, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x13,
+ static_cast<char>(0xBB), 0x0F, 0x25, 0x21, 0x4A, static_cast<char>(0xE4), \
static_cast<char>(0xB8), 0x03, + 0x00, 0x02, 0x46, 0x00, 0x0A, 0x6C, 0x6F, 0x61,
+ 0x64, 0x46, 0x61, 0x63, 0x74, 0x6F, 0x72, 0x49,
+ 0x00, 0x09, 0x74, 0x68, 0x72, 0x65, 0x73, 0x68,
+ 0x6F, 0x6C, 0x64, 0x78, 0x70 };
+ writeProlog("java.util.Hashtable", 1, prolog, sizeof(prolog), p);
+
+ // loadFactor = 0.75, threshold = 5, blockdata start, buckets.size = 7
+ char data[] = { 0x3F, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05,
+ TC_BLOCKDATA, 0x08, 0x00, 0x00, 0x00, 0x07 };
+ ByteBuffer dataBuf(data, sizeof(data));
+ os->write(dataBuf, p);
+
+ char size[4];
+ size_t sz = val.size();
+
+ size[3] = (char) (sz & 0xFF);
+ size[2] = (char) ((sz >> 8) & 0xFF);
+ size[1] = (char) ((sz >> 16) & 0xFF);
+ size[0] = (char) ((sz >> 24) & 0xFF);
+
+ ByteBuffer sizeBuf(size, sizeof(size));
+ os->write(sizeBuf, p);
+
+ for (MDC::Map::const_iterator iter = val.begin();
+ iter != val.end();
+ iter++)
+ {
+ writeObject(iter->first, p);
+ writeObject(iter->second, p);
+ }
+ writeByte(TC_ENDBLOCKDATA, p);
+}
+
+void ObjectOutputStream::writeUTFString(const std::string& val, Pool& p)
+{
+ char bytes[3];
+ size_t len = val.size();
+ ByteBuffer dataBuf(const_cast<char*>(val.data()), val.size());
+ objectHandle++;
+
+ bytes[0] = 0x74;
+ bytes[1] = (char) ((len >> 8) & 0xFF);
+ bytes[2] = (char) (len & 0xFF);
+
+ ByteBuffer lenBuf(bytes, sizeof(bytes));
+ os->write(lenBuf, p);
+ os->write(dataBuf, p);
+}
+
+
+
+void ObjectOutputStream::writeByte(char val, Pool& p)
+{
+ ByteBuffer buf(&val, 1);
+ os->write(buf, p);
+}
+
+void ObjectOutputStream::writeInt(int val, Pool& p)
+{
+ char bytes[4];
+
+ bytes[3] = (char) (val & 0xFF);
+ bytes[2] = (char) ((val >> 8) & 0xFF);
+ bytes[1] = (char) ((val >> 16) & 0xFF);
+ bytes[0] = (char) ((val >> 24) & 0xFF);
+
+ ByteBuffer buf(bytes, sizeof(bytes));
+ os->write(buf, p);
+}
+
+void ObjectOutputStream::writeLong(log4cxx_time_t val, Pool& p)
+{
+ char bytes[8];
+
+ bytes[7] = (char) (val & 0xFF);
+ bytes[6] = (char) ((val >> 8) & 0xFF);
+ bytes[5] = (char) ((val >> 16) & 0xFF);
+ bytes[4] = (char) ((val >> 24) & 0xFF);
+ bytes[3] = (char) ((val >> 32) & 0xFF);
+ bytes[2] = (char) ((val >> 40) & 0xFF);
+ bytes[1] = (char) ((val >> 48) & 0xFF);
+ bytes[0] = (char) ((val >> 56) & 0xFF);
+
+ ByteBuffer buf(bytes, sizeof(bytes));
+ os->write(buf, p);
+}
+
+void ObjectOutputStream::writeBytes(const char* bytes, size_t len, Pool& p)
+{
+ ByteBuffer buf(const_cast<char*>(bytes), len);
+ os->write(buf, p);
+}
+
+void ObjectOutputStream::writeNull(Pool& p)
+{
+ writeByte(TC_NULL, p);
+}
+
+void ObjectOutputStream::writeProlog(const char* className,
+ int classDescIncrement,
+ char* classDesc,
+ size_t len,
+ Pool& p)
+{
+ ClassDescriptionMap::const_iterator match = classDescriptions->find(className);
+
+ if (match != classDescriptions->end())
+ {
+ char bytes[6];
+
+ bytes[0] = TC_OBJECT;
+ bytes[1] = TC_REFERENCE;
+ bytes[2] = (char) ((match->second >> 24) & 0xFF);
+ bytes[3] = (char) ((match->second >> 16) & 0xFF);
+ bytes[4] = (char) ((match->second >> 8) & 0xFF);
+ bytes[5] = (char) (match->second & 0xFF);
+
+ ByteBuffer buf(bytes, sizeof(bytes));
+ os->write(buf, p);
+
+ objectHandle++;
+ }
+ else
+ {
+ classDescriptions->insert(ClassDescriptionMap::value_type(className, \
objectHandle)); + writeByte(TC_OBJECT, p);
+
+ ByteBuffer buf(classDesc, len);
+ os->write(buf, p);
+
+ objectHandle += (classDescIncrement + 1);
+ }
+}
Modified: incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp?rev=1720193&r1=1720192&r2=1720193&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp (original)
+++ incubator/log4cxx/trunk/src/main/cpp/socketappender.cpp Tue Dec 15 16:53:54 2015
@@ -38,74 +38,93 @@ IMPLEMENT_LOG4CXX_OBJECT(SocketAppender)
// The default port number of remote logging server (4560)
-int SocketAppender::DEFAULT_PORT = 4560;
+int SocketAppender::DEFAULT_PORT = 4560;
// The default reconnection delay (30000 milliseconds or 30 seconds).
-int SocketAppender::DEFAULT_RECONNECTION_DELAY = 30000;
-
-
+int SocketAppender::DEFAULT_RECONNECTION_DELAY = 30000;
SocketAppender::SocketAppender()
-: SocketAppenderSkeleton(DEFAULT_PORT, DEFAULT_RECONNECTION_DELAY) {
+: SocketAppenderSkeleton(DEFAULT_PORT, DEFAULT_RECONNECTION_DELAY)
+{
}
SocketAppender::SocketAppender(InetAddressPtr& address1, int port1)
-: SocketAppenderSkeleton(address1, port1, DEFAULT_RECONNECTION_DELAY) {
- Pool p;
- activateOptions(p);
+: SocketAppenderSkeleton(address1, port1, DEFAULT_RECONNECTION_DELAY)
+{
+ Pool p;
+ activateOptions(p);
}
SocketAppender::SocketAppender(const LogString& host, int port1)
-: SocketAppenderSkeleton(host, port1, DEFAULT_RECONNECTION_DELAY) {
- Pool p;
- activateOptions(p);
+: SocketAppenderSkeleton(host, port1, DEFAULT_RECONNECTION_DELAY)
+{
+ Pool p;
+ activateOptions(p);
}
SocketAppender::~SocketAppender()
{
- finalize();
+ finalize();
+}
+
+int SocketAppender::getDefaultDelay() const
+{
+ return DEFAULT_RECONNECTION_DELAY;
}
-int SocketAppender::getDefaultDelay() const {
- return DEFAULT_RECONNECTION_DELAY;
+int SocketAppender::getDefaultPort() const
+{
+ return DEFAULT_PORT;
}
-int SocketAppender::getDefaultPort() const {
- return DEFAULT_PORT;
-}
-
-void SocketAppender::setSocket(log4cxx::helpers::SocketPtr& socket, Pool& p) {
- synchronized sync(mutex);
- oos = new ObjectOutputStream(new SocketOutputStream(socket), p);
-}
-
-void SocketAppender::cleanUp(Pool& p) {
- if (oos != 0) {
- try {
- oos->close(p);
- oos = 0;
- } catch(std::exception& e) {
- }
- }
+void SocketAppender::setSocket(log4cxx::helpers::SocketPtr& socket, Pool& p)
+{
+ synchronized sync(mutex);
+
+ oos = new ObjectOutputStream(new SocketOutputStream(socket), p);
}
+void SocketAppender::cleanUp(Pool& p)
+{
+ if (oos == 0)
+ {
+ return;
+ }
+
+ try
+ {
+ oos->close(p);
+ oos = 0;
+ }
+ catch(std::exception& e)
+ {}
+}
-void SocketAppender::append(const spi::LoggingEventPtr& event, \
log4cxx::helpers::Pool& p) {
- if (oos != 0) {
- LogString ndcVal;
- event->getNDC(ndcVal);
- event->getThreadName();
- // Get a copy of this thread's MDC.
- event->getMDCCopy();
- try {
- event->write(*oos, p);
- oos->flush(p);
- } catch(std::exception& e) {
- oos = 0;
- LogLog::warn(LOG4CXX_STR("Detected problem with connection: "), e);
- if (getReconnectionDelay() > 0) {
- fireConnector();
- }
- }
- }
+void SocketAppender::append(const spi::LoggingEventPtr& event, \
log4cxx::helpers::Pool& p) +{
+ if (oos == 0)
+ {
+ return;
+ }
+
+ LogString ndcVal;
+ event->getNDC(ndcVal);
+ event->getThreadName();
+ event->getMDCCopy();
+
+ try
+ {
+ event->write(*oos, p);
+ oos->flush(p);
+ }
+ catch(std::exception& e)
+ {
+ oos = 0;
+ LogLog::warn(LOG4CXX_STR("Detected problem with connection: "), e);
+
+ if (getReconnectionDelay() > 0)
+ {
+ fireConnector();
+ }
+ }
}
Modified: incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h?rev=1720193&r1=1720192&r2=1720193&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h \
(original)
+++ incubator/log4cxx/trunk/src/main/include/log4cxx/helpers/objectoutputstream.h Tue \
Dec 15 16:53:54 2015 @@ -25,71 +25,74 @@
namespace log4cxx
{
+ namespace helpers
+ {
+ /**
+ * Emulates java serialization.
+ */
+ class LOG4CXX_EXPORT ObjectOutputStream : public ObjectImpl
+ {
+ public:
+ DECLARE_ABSTRACT_LOG4CXX_OBJECT(ObjectOutputStream)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(ObjectOutputStream)
+ END_LOG4CXX_CAST_MAP()
+
+ ObjectOutputStream(OutputStreamPtr os, Pool& p);
+ virtual ~ObjectOutputStream();
+
+ void close(Pool& p);
+ void flush(Pool& p);
+ void writeObject(const LogString&, Pool& p);
+ void writeUTFString(const std::string&, Pool& p);
+ void writeObject(const MDC::Map& mdc, Pool& p);
+ void writeInt(int val, Pool& p);
+ void writeLong(log4cxx_time_t val, Pool& p);
+ void writeProlog(const char* className,
+ int classDescIncrement,
+ char* bytes,
+ size_t len,
+ Pool& p);
+ void writeNull(Pool& p);
+
+ enum { STREAM_MAGIC = 0xACED };
+ enum { STREAM_VERSION = 5 };
+ enum
+ {
+ TC_NULL = 0x70,
+ TC_REFERENCE = 0x71,
+ TC_CLASSDESC = 0x72,
+ TC_OBJECT = 0x73,
+ TC_STRING = 0x74,
+ TC_ARRAY = 0x75,
+ TC_CLASS = 0x76,
+ TC_BLOCKDATA = 0x77,
+ TC_ENDBLOCKDATA = 0x78
+ };
+ enum
+ {
+ SC_WRITE_METHOD = 0x01,
+ SC_SERIALIZABLE = 0x02
+ };
+
+ void writeByte(char val, Pool& p);
+ void writeBytes(const char* bytes, size_t len, Pool& p);
+
+ private:
+ ObjectOutputStream(const ObjectOutputStream&);
+ ObjectOutputStream& operator=(const ObjectOutputStream&);
+
+ OutputStreamPtr os;
+ log4cxx::helpers::CharsetEncoderPtr utf8Encoder;
+ unsigned int objectHandle;
+ typedef std::map<std::string, unsigned int> ClassDescriptionMap;
+ ClassDescriptionMap* classDescriptions;
+ };
- namespace helpers {
+ LOG4CXX_PTR_DEF(ObjectOutputStream);
+ } // namespace helpers
- /**
- * Emulates java serialization.
- */
- class LOG4CXX_EXPORT ObjectOutputStream : public ObjectImpl
- {
- public:
- DECLARE_ABSTRACT_LOG4CXX_OBJECT(ObjectOutputStream)
- BEGIN_LOG4CXX_CAST_MAP()
- LOG4CXX_CAST_ENTRY(ObjectOutputStream)
- END_LOG4CXX_CAST_MAP()
-
- ObjectOutputStream(OutputStreamPtr os, Pool& p);
- virtual ~ObjectOutputStream();
-
- void close(Pool& p);
- void flush(Pool& p);
- void writeObject(const LogString&, Pool& p);
- void writeUTFString(const std::string&, Pool& p);
- void writeObject(const MDC::Map& mdc, Pool& p);
- void writeInt(int val, Pool& p);
- void writeLong(log4cxx_time_t val, Pool& p);
- void writeProlog(const char* className,
- int classDescIncrement,
- char* bytes,
- size_t len,
- Pool& p);
- void writeNull(Pool& p);
-
- enum { STREAM_MAGIC = 0xACED };
- enum { STREAM_VERSION = 5 };
- enum { TC_NULL = 0x70,
- TC_REFERENCE = 0x71,
- TC_CLASSDESC = 0x72,
- TC_OBJECT = 0x73,
- TC_STRING = 0x74,
- TC_ARRAY = 0x75,
- TC_CLASS = 0x76,
- TC_BLOCKDATA = 0x77,
- TC_ENDBLOCKDATA = 0x78 };
- enum {
- SC_WRITE_METHOD = 0x01,
- SC_SERIALIZABLE = 0x02 };
-
- void writeByte(char val, Pool& p);
- void writeBytes(const char* bytes, size_t len, Pool& p);
-
- private:
- ObjectOutputStream(const ObjectOutputStream&);
- ObjectOutputStream& operator=(const ObjectOutputStream&);
-
- OutputStreamPtr os;
- log4cxx::helpers::CharsetEncoderPtr utf8Encoder;
- unsigned int objectHandle;
- typedef std::map<std::string, unsigned int> ClassDescriptionMap;
- ClassDescriptionMap* classDescriptions;
- };
-
- LOG4CXX_PTR_DEF(ObjectOutputStream);
-
- } // namespace helpers
-
-} //namespace log4cxx
+} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_OUTPUTSTREAM_H
Modified: incubator/log4cxx/trunk/src/main/include/log4cxx/net/socketappender.h
URL: http://svn.apache.org/viewvc/incubator/log4cxx/trunk/src/main/include/log4cxx/net/socketappender.h?rev=1720193&r1=1720192&r2=1720193&view=diff
==============================================================================
--- incubator/log4cxx/trunk/src/main/include/log4cxx/net/socketappender.h (original)
+++ incubator/log4cxx/trunk/src/main/include/log4cxx/net/socketappender.h Tue Dec 15 \
16:53:54 2015 @@ -23,120 +23,112 @@
namespace log4cxx
{
- namespace net
- {
+ namespace net
+ {
+ /**
+ Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects to a remote a log \
server, + usually Apache Chainsaw.
+
+ <p>The SocketAppender has the following properties:
+
+ - If sent to Apache Chainsaw, remote logging
+ is non-intrusive as far as the log event is concerned. In other
+ words, the event will be logged with the same time stamp, {@link
+ NDC NDC}, location info as if it were logged locally by
+ the client.
+
+ - SocketAppenders do not use a layout. They ship a
+ serialized {@link log4cxx::spi::LoggingEvent LoggingEvent} object
+ to the server side.
+
+ - Remote logging uses the TCP protocol. Consequently, if
+ the server is reachable, then log events will eventually arrive
+ at the server.
+
+ - If the remote server is down, the logging requests are
+ simply dropped. However, if and when the server comes back up,
+ then event transmission is resumed transparently. This
+ transparent reconneciton is performed by a <em>connector</em>
+ thread which periodically attempts to connect to the server.
+
+ - Logging events are automatically <em>buffered</em> by the
+ native TCP implementation. This means that if the link to server
+ is slow but still faster than the rate of (log) event production
+ by the client, the client will not be affected by the slow
+ network connection. However, if the network connection is slower
+ then the rate of event production, then the client can only
+ progress at the network rate. In particular, if the network link
+ to the the server is down, the client will be blocked.
+ @n @n On the other hand, if the network link is up, but the server
+ is down, the client will not be blocked when making log requests
+ but the log events will be lost due to server unavailability.
+
+ - Even if a <code>SocketAppender</code> is no longer
+ attached to any logger, it will not be destroyed in
+ the presence of a connector thread. A connector thread exists
+ only if the connection to the server is down. To avoid this
+ destruction problem, you should #close the the
+ <code>SocketAppender</code> explicitly. See also next item.
+ @n @n Long lived applications which create/destroy many
+ <code>SocketAppender</code> instances should be aware of this
+ destruction problem. Most other applications can safely
+ ignore it.
+
+ - If the application hosting the <code>SocketAppender</code>
+ exits before the <code>SocketAppender</code> is closed either
+ explicitly or subsequent to destruction, then there might
+ be untransmitted data in the pipe which might be lost.
+ @n @n To avoid lost data, it is usually sufficient to
+ #close the <code>SocketAppender</code> either explicitly or by
+ calling the LogManager#shutdown method
+ before exiting the application.
+ */
+ class LOG4CXX_EXPORT SocketAppender : public SocketAppenderSkeleton
+ {
+ public:
+ /**
+ The default port number of remote logging server (4560).
+ */
+ static int DEFAULT_PORT;
+
+ /**
+ The default reconnection delay (30000 milliseconds or 30 seconds).
+ */
+ static int DEFAULT_RECONNECTION_DELAY;
+
+ DECLARE_LOG4CXX_OBJECT(SocketAppender)
+ BEGIN_LOG4CXX_CAST_MAP()
+ LOG4CXX_CAST_ENTRY(SocketAppender)
+ LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
+ END_LOG4CXX_CAST_MAP()
+
+ SocketAppender();
+ ~SocketAppender();
+
+ /**
+ Connects to remote server at <code>address</code> and <code>port</code>.
+ */
+ SocketAppender(helpers::InetAddressPtr& address, int port);
+
+ /**
+ Connects to remote server at <code>host</code> and <code>port</code>.
+ */
+ SocketAppender(const LogString& host, int port);
+
+ protected:
+ virtual void setSocket(log4cxx::helpers::SocketPtr& socket, \
log4cxx::helpers::Pool& p); + virtual void cleanUp(log4cxx::helpers::Pool& p);
+ virtual int getDefaultDelay() const;
+ virtual int getDefaultPort() const;
+ void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool);
- /**
- Sends {@link log4cxx::spi::LoggingEvent LoggingEvent} objects to a remote a \
log server,
- usually Apache Chainsaw.
-
- <p>The SocketAppender has the following properties:
-
- - If sent to Apache Chainsaw, remote logging
- is non-intrusive as far as the log event is concerned. In other
- words, the event will be logged with the same time stamp, {@link
- NDC NDC}, location info as if it were logged locally by
- the client.
-
- - SocketAppenders do not use a layout. They ship a
- serialized {@link log4cxx::spi::LoggingEvent LoggingEvent} object
- to the server side.
-
- - Remote logging uses the TCP protocol. Consequently, if
- the server is reachable, then log events will eventually arrive
- at the server.
-
- - If the remote server is down, the logging requests are
- simply dropped. However, if and when the server comes back up,
- then event transmission is resumed transparently. This
- transparent reconneciton is performed by a <em>connector</em>
- thread which periodically attempts to connect to the server.
-
- - Logging events are automatically <em>buffered</em> by the
- native TCP implementation. This means that if the link to server
- is slow but still faster than the rate of (log) event production
- by the client, the client will not be affected by the slow
- network connection. However, if the network connection is slower
- then the rate of event production, then the client can only
- progress at the network rate. In particular, if the network link
- to the the server is down, the client will be blocked.
- @n @n On the other hand, if the network link is up, but the server
- is down, the client will not be blocked when making log requests
- but the log events will be lost due to server unavailability.
-
- - Even if a <code>SocketAppender</code> is no longer
- attached to any logger, it will not be destroyed in
- the presence of a connector thread. A connector thread exists
- only if the connection to the server is down. To avoid this
- destruction problem, you should #close the the
- <code>SocketAppender</code> explicitly. See also next item.
- @n @n Long lived applications which create/destroy many
- <code>SocketAppender</code> instances should be aware of this
- destruction problem. Most other applications can safely
- ignore it.
-
- - If the application hosting the <code>SocketAppender</code>
- exits before the <code>SocketAppender</code> is closed either
- explicitly or subsequent to destruction, then there might
- be untransmitted data in the pipe which might be lost.
- @n @n To avoid lost data, it is usually sufficient to
- #close the <code>SocketAppender</code> either explicitly or by
- calling the LogManager#shutdown method
- before exiting the application.
- */
-
- class LOG4CXX_EXPORT SocketAppender : public SocketAppenderSkeleton
- {
- public:
- /**
- The default port number of remote logging server (4560).
- */
- static int DEFAULT_PORT;
-
- /**
- The default reconnection delay (30000 milliseconds or 30 seconds).
- */
- static int DEFAULT_RECONNECTION_DELAY;
-
- DECLARE_LOG4CXX_OBJECT(SocketAppender)
- BEGIN_LOG4CXX_CAST_MAP()
- LOG4CXX_CAST_ENTRY(SocketAppender)
- LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
- END_LOG4CXX_CAST_MAP()
-
- SocketAppender();
- ~SocketAppender();
-
- /**
- Connects to remote server at <code>address</code> and \
<code>port</code>.
- */
- SocketAppender(helpers::InetAddressPtr& address, int port);
-
- /**
- Connects to remote server at <code>host</code> and \
<code>port</code>.
- */
- SocketAppender(const LogString& host, int port);
-
-
- protected:
- virtual void setSocket(log4cxx::helpers::SocketPtr& socket, \
log4cxx::helpers::Pool& p);
-
- virtual void cleanUp(log4cxx::helpers::Pool& p);
-
- virtual int getDefaultDelay() const;
-
- virtual int getDefaultPort() const;
-
- void append(const spi::LoggingEventPtr& event, \
log4cxx::helpers::Pool& pool);
-
- private:
- log4cxx::helpers::ObjectOutputStreamPtr oos;
-
- }; // class SocketAppender
-
- LOG4CXX_PTR_DEF(SocketAppender);
-
- } // namespace net
+ private:
+ log4cxx::helpers::ObjectOutputStreamPtr oos;
+
+ }; // class SocketAppender
+
+ LOG4CXX_PTR_DEF(SocketAppender);
+ } // namespace net
} // namespace log4cxx
#endif // _LOG4CXX_NET_SOCKET_APPENDER_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic