You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rm...@apache.org on 2021/11/06 00:43:18 UTC
[logging-log4cxx] 13/20: made LoggingEvent ABI stable and removed
some serialization tests
This is an automated email from the ASF dual-hosted git repository.
rmiddleton pushed a commit to branch LOGCXX-510
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git
commit 0aaa197eb1d3f69660692b5b9f26145ee87c0d8f
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Fri Nov 5 18:26:45 2021 -0400
made LoggingEvent ABI stable and removed some serialization tests
---
src/main/cpp/hierarchy.cpp | 163 +++++++------
src/main/cpp/loggingevent.cpp | 270 ++++++++++-----------
src/main/cpp/sockethubappender.cpp | 2 +-
src/main/include/log4cxx/spi/loggingevent.h | 94 +------
src/test/cpp/CMakeLists.txt | 1 -
src/test/cpp/spi/CMakeLists.txt | 2 -
src/test/cpp/spi/loggingeventtest.cpp | 126 ----------
src/test/cpp/util/CMakeLists.txt | 1 -
src/test/cpp/util/serializationtesthelper.cpp | 88 -------
src/test/cpp/util/serializationtesthelper.h | 44 ----
.../resources/witness/serialization/exception.bin | Bin 1843 -> 0 bytes
src/test/resources/witness/serialization/info.bin | Bin 60 -> 0 bytes
.../resources/witness/serialization/location.bin | Bin 465 -> 0 bytes
src/test/resources/witness/serialization/mdc.bin | Bin 508 -> 0 bytes
src/test/resources/witness/serialization/ndc.bin | Bin 409 -> 0 bytes
.../resources/witness/serialization/simple.bin | Bin 399 -> 0 bytes
16 files changed, 238 insertions(+), 553 deletions(-)
diff --git a/src/main/cpp/hierarchy.cpp b/src/main/cpp/hierarchy.cpp
index 89c3a8d..4be5f49 100644
--- a/src/main/cpp/hierarchy.cpp
+++ b/src/main/cpp/hierarchy.cpp
@@ -45,21 +45,48 @@ using namespace log4cxx;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;
+
+typedef std::map<LogString, LoggerPtr> LoggerMap;
+typedef std::map<LogString, ProvisionNode> ProvisionNodeMap;
+
+struct Hierarchy::HierarchyPrivate {
+ HierarchyPrivate(){
+ loggers = std::make_unique<LoggerMap>();
+ provisionNodes = std::make_unique<ProvisionNodeMap>();
+ root = std::make_shared<RootLogger>(pool, Level::getDebug());
+ defaultFactory = std::make_shared<DefaultLoggerFactory>();
+ emittedNoAppenderWarning = false;
+ configured = false;
+ thresholdInt = Level::ALL_INT;
+ threshold = Level::getAll();
+ emittedNoResourceBundleWarning = false;
+ }
+
+ log4cxx::helpers::Pool pool;
+ mutable std::mutex mutex;
+ bool configured;
+
+ spi::LoggerFactoryPtr defaultFactory;
+ spi::HierarchyEventListenerList listeners;
+
+ std::unique_ptr<LoggerMap> loggers;
+
+ std::unique_ptr<ProvisionNodeMap> provisionNodes;
+
+ LoggerPtr root;
+
+ int thresholdInt;
+ LevelPtr threshold;
+
+ bool emittedNoAppenderWarning;
+ bool emittedNoResourceBundleWarning;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(Hierarchy)
Hierarchy::Hierarchy() :
- pool(),
- loggers(new LoggerMap()),
- provisionNodes(new ProvisionNodeMap())
+ m_priv(std::make_unique<HierarchyPrivate>())
{
- std::unique_lock<std::mutex> lock(mutex);
- root = LoggerPtr(new RootLogger(pool, Level::getDebug()));
- defaultFactory = LoggerFactoryPtr(new DefaultLoggerFactory());
- emittedNoAppenderWarning = false;
- configured = false;
- thresholdInt = Level::ALL_INT;
- threshold = Level::getAll();
- emittedNoResourceBundleWarning = false;
}
Hierarchy::~Hierarchy()
@@ -74,31 +101,31 @@ Hierarchy::~Hierarchy()
void Hierarchy::addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener)
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
- if (std::find(listeners.begin(), listeners.end(), listener) != listeners.end())
+ if (std::find(m_priv->listeners.begin(), m_priv->listeners.end(), listener) != m_priv->listeners.end())
{
LogLog::warn(LOG4CXX_STR("Ignoring attempt to add an existent listener."));
}
else
{
- listeners.push_back(listener);
+ m_priv->listeners.push_back(listener);
}
}
void Hierarchy::clear()
{
- std::unique_lock<std::mutex> lock(mutex);
- loggers->clear();
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ m_priv->loggers->clear();
}
void Hierarchy::emitNoAppenderWarning(const Logger* logger)
{
bool emitWarning = false;
{
- std::unique_lock<std::mutex> lock(mutex);
- emitWarning = !emittedNoAppenderWarning;
- emittedNoAppenderWarning = true;
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ emitWarning = !m_priv->emittedNoAppenderWarning;
+ m_priv->emittedNoAppenderWarning = true;
}
// No appender in hierarchy, warn user only once.
@@ -113,12 +140,12 @@ void Hierarchy::emitNoAppenderWarning(const Logger* logger)
LoggerPtr Hierarchy::exists(const LogString& name)
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
LoggerPtr logger;
- LoggerMap::iterator it = loggers->find(name);
+ LoggerMap::iterator it = m_priv->loggers->find(name);
- if (it != loggers->end())
+ if (it != m_priv->loggers->end())
{
logger = it->second;
}
@@ -131,7 +158,7 @@ void Hierarchy::setThreshold(const LevelPtr& l)
{
if (l != 0)
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
setThresholdInternal(l);
}
}
@@ -153,12 +180,12 @@ void Hierarchy::setThreshold(const LogString& levelStr)
void Hierarchy::setThresholdInternal(const LevelPtr& l)
{
- thresholdInt = l->toInt();
- threshold = l;
+ m_priv->thresholdInt = l->toInt();
+ m_priv->threshold = l;
- if (thresholdInt != Level::ALL_INT)
+ if (m_priv->thresholdInt != Level::ALL_INT)
{
- configured = true;
+ m_priv->configured = true;
}
}
@@ -167,8 +194,8 @@ void Hierarchy::fireAddAppenderEvent(const Logger* logger, const Appender* appen
setConfigured(true);
HierarchyEventListenerList clonedList;
{
- std::unique_lock<std::mutex> lock(mutex);
- clonedList = listeners;
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ clonedList = m_priv->listeners;
}
HierarchyEventListenerList::iterator it, itEnd = clonedList.end();
@@ -186,8 +213,8 @@ void Hierarchy::fireRemoveAppenderEvent(const Logger* logger, const Appender* ap
{
HierarchyEventListenerList clonedList;
{
- std::unique_lock<std::mutex> lock(mutex);
- clonedList = listeners;
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ clonedList = m_priv->listeners;
}
HierarchyEventListenerList::iterator it, itEnd = clonedList.end();
HierarchyEventListenerPtr listener;
@@ -201,37 +228,37 @@ void Hierarchy::fireRemoveAppenderEvent(const Logger* logger, const Appender* ap
const LevelPtr& Hierarchy::getThreshold() const
{
- return threshold;
+ return m_priv->threshold;
}
LoggerPtr Hierarchy::getLogger(const LogString& name)
{
- return getLogger(name, defaultFactory);
+ return getLogger(name, m_priv->defaultFactory);
}
LoggerPtr Hierarchy::getLogger(const LogString& name,
const spi::LoggerFactoryPtr& factory)
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
- LoggerMap::iterator it = loggers->find(name);
+ LoggerMap::iterator it = m_priv->loggers->find(name);
- if (it != loggers->end())
+ if (it != m_priv->loggers->end())
{
return it->second;
}
else
{
- LoggerPtr logger(factory->makeNewLoggerInstance(pool, name));
+ LoggerPtr logger(factory->makeNewLoggerInstance(m_priv->pool, name));
logger->setHierarchy(shared_from_this());
- loggers->insert(LoggerMap::value_type(name, logger));
+ m_priv->loggers->insert(LoggerMap::value_type(name, logger));
- ProvisionNodeMap::iterator it2 = provisionNodes->find(name);
+ ProvisionNodeMap::iterator it2 = m_priv->provisionNodes->find(name);
- if (it2 != provisionNodes->end())
+ if (it2 != m_priv->provisionNodes->end())
{
updateChildren(it2->second, logger);
- provisionNodes->erase(it2);
+ m_priv->provisionNodes->erase(it2);
}
updateParents(logger);
@@ -242,12 +269,12 @@ LoggerPtr Hierarchy::getLogger(const LogString& name,
LoggerList Hierarchy::getCurrentLoggers() const
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
LoggerList v;
- LoggerMap::const_iterator it, itEnd = loggers->end();
+ LoggerMap::const_iterator it, itEnd = m_priv->loggers->end();
- for (it = loggers->begin(); it != itEnd; it++)
+ for (it = m_priv->loggers->begin(); it != itEnd; it++)
{
v.push_back(it->second);
}
@@ -258,15 +285,15 @@ LoggerList Hierarchy::getCurrentLoggers() const
LoggerPtr Hierarchy::getRootLogger() const
{
- return root;
+ return m_priv->root;
}
bool Hierarchy::isDisabled(int level) const
{
bool currentlyConfigured;
{
- std::unique_lock<std::mutex> lock(mutex);
- currentlyConfigured = configured;
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ currentlyConfigured = m_priv->configured;
}
if (!currentlyConfigured)
@@ -276,23 +303,23 @@ bool Hierarchy::isDisabled(int level) const
nonconstThis);
}
- return thresholdInt > level;
+ return m_priv->thresholdInt > level;
}
void Hierarchy::resetConfiguration()
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
getRootLogger()->setLevel(Level::getDebug());
- root->setResourceBundle(0);
+ m_priv->root->setResourceBundle(0);
setThresholdInternal(Level::getAll());
shutdownInternal();
- LoggerMap::const_iterator it, itEnd = loggers->end();
+ LoggerMap::const_iterator it, itEnd = m_priv->loggers->end();
- for (it = loggers->begin(); it != itEnd; it++)
+ for (it = m_priv->loggers->begin(); it != itEnd; it++)
{
it->second->setLevel(0);
it->second->setAdditivity(true);
@@ -304,23 +331,23 @@ void Hierarchy::resetConfiguration()
void Hierarchy::shutdown()
{
- std::unique_lock<std::mutex> lock(mutex);
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
shutdownInternal();
}
void Hierarchy::shutdownInternal()
{
- configured = false;
+ m_priv->configured = false;
LoggerPtr root1 = getRootLogger();
// begin by closing nested appenders
root1->closeNestedAppenders();
- LoggerMap::iterator it, itEnd = loggers->end();
+ LoggerMap::iterator it, itEnd = m_priv->loggers->end();
- for (it = loggers->begin(); it != itEnd; it++)
+ for (it = m_priv->loggers->begin(); it != itEnd; it++)
{
LoggerPtr logger = it->second;
logger->closeNestedAppenders();
@@ -329,7 +356,7 @@ void Hierarchy::shutdownInternal()
// then, remove all appenders
root1->removeAllAppenders();
- for (it = loggers->begin(); it != itEnd; it++)
+ for (it = m_priv->loggers->begin(); it != itEnd; it++)
{
LoggerPtr logger = it->second;
logger->removeAllAppenders();
@@ -350,9 +377,9 @@ void Hierarchy::updateParents(LoggerPtr logger)
{
LogString substr = name.substr(0, i);
- LoggerMap::iterator it = loggers->find(substr);
+ LoggerMap::iterator it = m_priv->loggers->find(substr);
- if (it != loggers->end())
+ if (it != m_priv->loggers->end())
{
parentFound = true;
logger->setParent( it->second );
@@ -360,16 +387,16 @@ void Hierarchy::updateParents(LoggerPtr logger)
}
else
{
- ProvisionNodeMap::iterator it2 = provisionNodes->find(substr);
+ ProvisionNodeMap::iterator it2 = m_priv->provisionNodes->find(substr);
- if (it2 != provisionNodes->end())
+ if (it2 != m_priv->provisionNodes->end())
{
it2->second.push_back(logger);
}
else
{
ProvisionNode node(1, logger);
- provisionNodes->insert(
+ m_priv->provisionNodes->insert(
ProvisionNodeMap::value_type(substr, node));
}
}
@@ -378,7 +405,7 @@ void Hierarchy::updateParents(LoggerPtr logger)
// If we could not find any existing parents, then link with root.
if (!parentFound)
{
- logger->setParent( root );
+ logger->setParent( m_priv->root );
}
}
@@ -403,13 +430,13 @@ void Hierarchy::updateChildren(ProvisionNode& pn, LoggerPtr logger)
void Hierarchy::setConfigured(bool newValue)
{
- std::unique_lock<std::mutex> lock(mutex);
- configured = newValue;
+ std::unique_lock<std::mutex> lock(m_priv->mutex);
+ m_priv->configured = newValue;
}
bool Hierarchy::isConfigured()
{
- return configured;
+ return m_priv->configured;
}
HierarchyPtr Hierarchy::create(){
@@ -422,7 +449,7 @@ void Hierarchy::configureRoot(){
// This should really be done in the constructor, but in order to fix
// LOGCXX-322 we need to turn the repositroy into a weak_ptr, and we
// can't use weak_from_this() in the constructor.
- if( !root->getLoggerRepository().lock() ){
- root->setHierarchy(shared_from_this());
+ if( !m_priv->root->getLoggerRepository().lock() ){
+ m_priv->root->setHierarchy(shared_from_this());
}
}
diff --git a/src/main/cpp/loggingevent.cpp b/src/main/cpp/loggingevent.cpp
index 98056d5..bcec1b1 100644
--- a/src/main/cpp/loggingevent.cpp
+++ b/src/main/cpp/loggingevent.cpp
@@ -42,6 +42,90 @@ using namespace log4cxx;
using namespace log4cxx::spi;
using namespace log4cxx::helpers;
+struct LoggingEvent::LoggingEventPrivate{
+ LoggingEventPrivate() :
+ ndc(0),
+ mdcCopy(0),
+ properties(0),
+ ndcLookupRequired(true),
+ mdcCopyLookupRequired(true),
+ timeStamp(0),
+ locationInfo()
+ {
+ }
+
+ LoggingEventPrivate(
+ const LogString& logger1, const LevelPtr& level1,
+ const LogString& message1, const LocationInfo& locationInfo1) :
+ logger(logger1),
+ level(level1),
+ ndc(0),
+ mdcCopy(0),
+ properties(0),
+ ndcLookupRequired(true),
+ mdcCopyLookupRequired(true),
+ message(message1),
+ timeStamp(apr_time_now()),
+ locationInfo(locationInfo1),
+ threadName(getCurrentThreadName()){}
+
+ ~LoggingEventPrivate(){
+ delete ndc;
+ delete mdcCopy;
+ delete properties;
+ }
+
+ /**
+ * The logger of the logging event.
+ **/
+ LogString logger;
+
+ /** level of logging event. */
+ LevelPtr level;
+
+ /** The nested diagnostic context (NDC) of logging event. */
+ mutable LogString* ndc;
+
+ /** The mapped diagnostic context (MDC) of logging event. */
+ mutable MDC::Map* mdcCopy;
+
+ /**
+ * A map of String keys and String values.
+ */
+ std::map<LogString, LogString>* properties;
+
+ /** Have we tried to do an NDC lookup? If we did, there is no need
+ * to do it again. Note that its value is always false when
+ * serialized. Thus, a receiving SocketNode will never use it's own
+ * (incorrect) NDC. See also writeObject method.
+ */
+ mutable bool ndcLookupRequired;
+
+ /**
+ * Have we tried to do an MDC lookup? If we did, there is no need to do it
+ * again. Note that its value is always false when serialized. See also
+ * the getMDC and getMDCCopy methods.
+ */
+ mutable bool mdcCopyLookupRequired;
+
+ /** The application supplied message of logging event. */
+ LogString message;
+
+
+ /** The number of microseconds elapsed from 01.01.1970 until logging event
+ was created. */
+ log4cxx_time_t timeStamp;
+
+ /** The is the location where this log statement was written. */
+ const log4cxx::spi::LocationInfo locationInfo;
+
+
+ /** The identifier of thread in which this logging event
+ was generated.
+ */
+ const LogString threadName;
+};
+
IMPLEMENT_LOG4CXX_OBJECT(LoggingEvent)
@@ -54,56 +138,37 @@ log4cxx_time_t LoggingEvent::getStartTime()
}
LoggingEvent::LoggingEvent() :
- ndc(0),
- mdcCopy(0),
- properties(0),
- ndcLookupRequired(true),
- mdcCopyLookupRequired(true),
- timeStamp(0),
- locationInfo()
+ m_priv(std::make_unique<LoggingEventPrivate>())
{
}
LoggingEvent::LoggingEvent(
const LogString& logger1, const LevelPtr& level1,
const LogString& message1, const LocationInfo& locationInfo1) :
- logger(logger1),
- level(level1),
- ndc(0),
- mdcCopy(0),
- properties(0),
- ndcLookupRequired(true),
- mdcCopyLookupRequired(true),
- message(message1),
- timeStamp(apr_time_now()),
- locationInfo(locationInfo1),
- threadName(getCurrentThreadName())
+ m_priv(std::make_unique<LoggingEventPrivate>(logger1, level1, message1, locationInfo1))
{
}
LoggingEvent::~LoggingEvent()
{
- delete ndc;
- delete mdcCopy;
- delete properties;
}
bool LoggingEvent::getNDC(LogString& dest) const
{
- if (ndcLookupRequired)
+ if (m_priv->ndcLookupRequired)
{
- ndcLookupRequired = false;
+ m_priv->ndcLookupRequired = false;
LogString val;
if (NDC::get(val))
{
- ndc = new LogString(val);
+ m_priv->ndc = new LogString(val);
}
}
- if (ndc)
+ if (m_priv->ndc)
{
- dest.append(*ndc);
+ dest.append(*m_priv->ndc);
return true;
}
@@ -114,11 +179,11 @@ bool LoggingEvent::getMDC(const LogString& key, LogString& dest) const
{
// Note the mdcCopy is used if it exists. Otherwise we use the MDC
// that is associated with the thread.
- if (mdcCopy != 0 && !mdcCopy->empty())
+ if (m_priv->mdcCopy != 0 && !m_priv->mdcCopy->empty())
{
- MDC::Map::const_iterator it = mdcCopy->find(key);
+ MDC::Map::const_iterator it = m_priv->mdcCopy->find(key);
- if (it != mdcCopy->end())
+ if (it != m_priv->mdcCopy->end())
{
if (!it->second.empty())
{
@@ -136,11 +201,11 @@ LoggingEvent::KeySet LoggingEvent::getMDCKeySet() const
{
LoggingEvent::KeySet set;
- if (mdcCopy != 0 && !mdcCopy->empty())
+ if (m_priv->mdcCopy != 0 && !m_priv->mdcCopy->empty())
{
MDC::Map::const_iterator it;
- for (it = mdcCopy->begin(); it != mdcCopy->end(); it++)
+ for (it = m_priv->mdcCopy->begin(); it != m_priv->mdcCopy->end(); it++)
{
set.push_back(it->first);
@@ -166,33 +231,33 @@ LoggingEvent::KeySet LoggingEvent::getMDCKeySet() const
void LoggingEvent::getMDCCopy() const
{
- if (mdcCopyLookupRequired)
+ if (m_priv->mdcCopyLookupRequired)
{
- mdcCopyLookupRequired = false;
+ m_priv->mdcCopyLookupRequired = false;
// the clone call is required for asynchronous logging.
ThreadSpecificData* data = ThreadSpecificData::getCurrentData();
if (data != 0)
{
- mdcCopy = new MDC::Map(data->getMap());
+ m_priv->mdcCopy = new MDC::Map(data->getMap());
}
else
{
- mdcCopy = new MDC::Map();
+ m_priv->mdcCopy = new MDC::Map();
}
}
}
bool LoggingEvent::getProperty(const LogString& key, LogString& dest) const
{
- if (properties == 0)
+ if (m_priv->properties == 0)
{
return false;
}
- std::map<LogString, LogString>::const_iterator it = properties->find(key);
+ std::map<LogString, LogString>::const_iterator it = m_priv->properties->find(key);
- if (it != properties->end())
+ if (it != m_priv->properties->end())
{
dest.append(it->second);
return true;
@@ -205,11 +270,11 @@ LoggingEvent::KeySet LoggingEvent::getPropertyKeySet() const
{
LoggingEvent::KeySet set;
- if (properties != 0)
+ if (m_priv->properties != 0)
{
std::map<LogString, LogString>::const_iterator it;
- for (it = properties->begin(); it != properties->end(); it++)
+ for (it = m_priv->properties->begin(); it != m_priv->properties->end(); it++)
{
set.push_back(it->first);
}
@@ -250,115 +315,46 @@ const LogString LoggingEvent::getCurrentThreadName()
void LoggingEvent::setProperty(const LogString& key, const LogString& value)
{
- if (properties == 0)
+ if (m_priv->properties == 0)
{
- properties = new std::map<LogString, LogString>;
+ m_priv->properties = new std::map<LogString, LogString>;
}
- (*properties)[key] = value;
+ (*m_priv->properties)[key] = value;
+}
+
+const LevelPtr& LoggingEvent::getLevel() const
+{
+ return m_priv->level;
}
+const LogString& LoggingEvent::getLoggerName() const
+{
+ return m_priv->logger;
+}
+const LogString& LoggingEvent::getMessage() const
+{
+ return m_priv->message;
+}
-void LoggingEvent::writeProlog(ObjectOutputStream& os, Pool& p)
+const LogString& LoggingEvent::getRenderedMessage() const
{
- unsigned char classDesc[] =
- {
- 0x72, 0x00, 0x21,
- 0x6F, 0x72, 0x67, 0x2E, 0x61, 0x70, 0x61, 0x63,
- 0x68, 0x65, 0x2E, 0x6C, 0x6F, 0x67, 0x34, 0x6A,
- 0x2E, 0x73, 0x70, 0x69, 0x2E, 0x4C, 0x6F, 0x67,
- 0x67, 0x69, 0x6E, 0x67, 0x45, 0x76, 0x65, 0x6E,
- 0x74, 0xF3, 0xF2, 0xB9, 0x23, 0x74, 0x0B, 0xB5,
- 0x3F, 0x03, 0x00, 0x0A, 0x5A, 0x00, 0x15, 0x6D,
- 0x64, 0x63, 0x43, 0x6F, 0x70, 0x79, 0x4C, 0x6F,
- 0x6F, 0x6B, 0x75, 0x70, 0x52, 0x65, 0x71, 0x75,
- 0x69, 0x72, 0x65, 0x64, 0x5A, 0x00, 0x11, 0x6E,
- 0x64, 0x63, 0x4C, 0x6F, 0x6F, 0x6B, 0x75, 0x70,
- 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64,
- 0x4A, 0x00, 0x09, 0x74, 0x69, 0x6D, 0x65, 0x53,
- 0x74, 0x61, 0x6D, 0x70, 0x4C, 0x00, 0x0C, 0x63,
- 0x61, 0x74, 0x65, 0x67, 0x6F, 0x72, 0x79, 0x4E,
- 0x61, 0x6D, 0x65, 0x74, 0x00, 0x12, 0x4C, 0x6A,
- 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
- 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
- 0x4C, 0x00, 0x0C, 0x6C, 0x6F, 0x63, 0x61, 0x74,
- 0x69, 0x6F, 0x6E, 0x49, 0x6E, 0x66, 0x6F, 0x74,
- 0x00, 0x23, 0x4C, 0x6F, 0x72, 0x67, 0x2F, 0x61,
- 0x70, 0x61, 0x63, 0x68, 0x65, 0x2F, 0x6C, 0x6F,
- 0x67, 0x34, 0x6A, 0x2F, 0x73, 0x70, 0x69, 0x2F,
- 0x4C, 0x6F, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E,
- 0x49, 0x6E, 0x66, 0x6F, 0x3B, 0x4C, 0x00, 0x07,
- 0x6D, 0x64, 0x63, 0x43, 0x6F, 0x70, 0x79, 0x74,
- 0x00, 0x15, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F,
- 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x48, 0x61, 0x73,
- 0x68, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x3B, 0x4C,
- 0x00, 0x03, 0x6E, 0x64, 0x63,
- 0x74, 0x00, 0x12, 0x4C, 0x6A,
- 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
- 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
- 0x4C, 0x00, 0x0F, 0x72, 0x65, 0x6E,
- 0x64, 0x65, 0x72, 0x65, 0x64, 0x4D, 0x65, 0x73,
- 0x73, 0x61, 0x67, 0x65,
- 0x74, 0x00, 0x12, 0x4C, 0x6A,
- 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
- 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
- 0x4C, 0x00, 0x0A, 0x74, 0x68, 0x72, 0x65,
- 0x61, 0x64, 0x4E, 0x61, 0x6D, 0x65,
- 0x74, 0x00, 0x12, 0x4C, 0x6A,
- 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
- 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
- 0x4C, 0x00, 0x0D, 0x74, 0x68,
- 0x72, 0x6F, 0x77, 0x61, 0x62, 0x6C, 0x65, 0x49,
- 0x6E, 0x66, 0x6F, 0x74, 0x00, 0x2B, 0x4C, 0x6F,
- 0x72, 0x67, 0x2F, 0x61, 0x70, 0x61, 0x63, 0x68,
- 0x65, 0x2F, 0x6C, 0x6F, 0x67, 0x34, 0x6A, 0x2F,
- 0x73, 0x70, 0x69, 0x2F, 0x54, 0x68, 0x72, 0x6F,
- 0x77, 0x61, 0x62, 0x6C, 0x65, 0x49, 0x6E, 0x66,
- 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x69, 0x6F, 0x6E,
- 0x3B, 0x78, 0x70
- };
-
- os.writeProlog("org.apache.log4j.spi.LoggingEvent",
- 8, (char*) classDesc, sizeof(classDesc), p);
+ return m_priv->message;
}
-void LoggingEvent::write(helpers::ObjectOutputStream& os, Pool& p) const
+const LogString& LoggingEvent::getThreadName() const
{
- writeProlog(os, p);
- // mdc and ndc lookup required should always be false
- char lookupsRequired[] = { 0, 0 };
- os.writeBytes(lookupsRequired, sizeof(lookupsRequired), p);
- os.writeLong(timeStamp / 1000, p);
- os.writeObject(logger, p);
- locationInfo.write(os, p);
-
- if (mdcCopy == 0 || mdcCopy->size() == 0)
- {
- os.writeNull(p);
- }
- else
- {
- os.writeObject(*mdcCopy, p);
- }
+ return m_priv->threadName;
+}
- if (ndc == 0)
- {
- os.writeNull(p);
- }
- else
- {
- os.writeObject(*ndc, p);
- }
+log4cxx_time_t LoggingEvent::getTimeStamp() const
+{
+ return m_priv->timeStamp;
+}
- os.writeObject(message, p);
- os.writeObject(threadName, p);
- // throwable
- os.writeNull(p);
- os.writeByte(ObjectOutputStream::TC_BLOCKDATA, p);
- os.writeByte(0x04, p);
- os.writeInt(level->toInt(), p);
- os.writeNull(p);
- os.writeByte(ObjectOutputStream::TC_ENDBLOCKDATA, p);
+const log4cxx::spi::LocationInfo& LoggingEvent::getLocationInformation() const
+{
+ return m_priv->locationInfo;
}
diff --git a/src/main/cpp/sockethubappender.cpp b/src/main/cpp/sockethubappender.cpp
index 2352504..2508dce 100644
--- a/src/main/cpp/sockethubappender.cpp
+++ b/src/main/cpp/sockethubappender.cpp
@@ -179,7 +179,7 @@ void SocketHubAppender::append(const spi::LoggingEventPtr& event, Pool& p)
try
{
- event->write(**it, p);
+// event->write(**it, p);
(*it)->flush(p);
it++;
}
diff --git a/src/main/include/log4cxx/spi/loggingevent.h b/src/main/include/log4cxx/spi/loggingevent.h
index 6e40103..635c188 100644
--- a/src/main/include/log4cxx/spi/loggingevent.h
+++ b/src/main/include/log4cxx/spi/loggingevent.h
@@ -83,28 +83,16 @@ class LOG4CXX_EXPORT LoggingEvent :
~LoggingEvent();
/** Return the level of this event. */
- inline const LevelPtr& getLevel() const
- {
- return level;
- }
+ const LevelPtr& getLevel() const;
/** Return the name of the logger. */
- inline const LogString& getLoggerName() const
- {
- return logger;
- }
+ const LogString& getLoggerName() const;
/** Return the message for this logging event. */
- inline const LogString& getMessage() const
- {
- return message;
- }
+ const LogString& getMessage() const;
/** Return the message for this logging event. */
- inline const LogString& getRenderedMessage() const
- {
- return message;
- }
+ const LogString& getRenderedMessage() const;
/**Returns the time when the application started,
in microseconds elapsed since 01.01.1970.
@@ -112,23 +100,14 @@ class LOG4CXX_EXPORT LoggingEvent :
static log4cxx_time_t getStartTime();
/** Return the threadName of this event. */
- inline const LogString& getThreadName() const
- {
- return threadName;
- }
+ const LogString& getThreadName() const;
/** The number of microseconds elapsed from 01.01.1970 until logging event
was created. */
- inline log4cxx_time_t getTimeStamp() const
- {
- return timeStamp;
- }
+ log4cxx_time_t getTimeStamp() const;
/* Return the file where this log statement was written. */
- inline const log4cxx::spi::LocationInfo& getLocationInformation() const
- {
- return locationInfo;
- }
+ const log4cxx::spi::LocationInfo& getLocationInformation() const;
/**
* This method appends the NDC for this event to passed string. It will return the
@@ -142,12 +121,6 @@ class LOG4CXX_EXPORT LoggingEvent :
bool getNDC(LogString& dest) const;
/**
- * Writes the content of the LoggingEvent
- * in a format compatible with log4j's serialized form.
- */
- void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
-
- /**
* Appends the the context corresponding to the <code>key</code> parameter.
* If there is a local MDC copy, possibly because we are in a logging
* server or running inside AsyncAppender, then we search for the key in
@@ -201,55 +174,8 @@ class LOG4CXX_EXPORT LoggingEvent :
void setProperty(const LogString& key, const LogString& value);
private:
- /**
- * The logger of the logging event.
- **/
- LogString logger;
-
- /** level of logging event. */
- LevelPtr level;
-
- /** The nested diagnostic context (NDC) of logging event. */
- mutable LogString* ndc;
-
- /** The mapped diagnostic context (MDC) of logging event. */
- mutable MDC::Map* mdcCopy;
-
- /**
- * A map of String keys and String values.
- */
- std::map<LogString, LogString>* properties;
-
- /** Have we tried to do an NDC lookup? If we did, there is no need
- * to do it again. Note that its value is always false when
- * serialized. Thus, a receiving SocketNode will never use it's own
- * (incorrect) NDC. See also writeObject method.
- */
- mutable bool ndcLookupRequired;
-
- /**
- * Have we tried to do an MDC lookup? If we did, there is no need to do it
- * again. Note that its value is always false when serialized. See also
- * the getMDC and getMDCCopy methods.
- */
- mutable bool mdcCopyLookupRequired;
-
- /** The application supplied message of logging event. */
- LogString message;
-
-
- /** The number of microseconds elapsed from 01.01.1970 until logging event
- was created. */
- log4cxx_time_t timeStamp;
-
- /** The is the location where this log statement was written. */
- const log4cxx::spi::LocationInfo locationInfo;
-
-
- /** The identifier of thread in which this logging event
- was generated.
- */
- const LogString threadName;
+ struct LoggingEventPrivate;
+ std::unique_ptr<LoggingEventPrivate> m_priv;
//
// prevent copy and assignment
@@ -258,8 +184,6 @@ class LOG4CXX_EXPORT LoggingEvent :
LoggingEvent& operator=(const LoggingEvent&);
static const LogString getCurrentThreadName();
- static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
-
};
LOG4CXX_PTR_DEF(LoggingEvent);
diff --git a/src/test/cpp/CMakeLists.txt b/src/test/cpp/CMakeLists.txt
index 29413d9..71f95be 100644
--- a/src/test/cpp/CMakeLists.txt
+++ b/src/test/cpp/CMakeLists.txt
@@ -57,7 +57,6 @@ if(WIN32)
endif()
add_subdirectory(pattern)
add_subdirectory(rolling)
-add_subdirectory(spi)
add_subdirectory(varia)
add_subdirectory(xml)
diff --git a/src/test/cpp/spi/CMakeLists.txt b/src/test/cpp/spi/CMakeLists.txt
deleted file mode 100644
index 380269f..0000000
--- a/src/test/cpp/spi/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-add_executable(spitestcase loggingeventtest.cpp)
-set(ALL_LOG4CXX_TESTS ${ALL_LOG4CXX_TESTS} spitestcase PARENT_SCOPE)
diff --git a/src/test/cpp/spi/loggingeventtest.cpp b/src/test/cpp/spi/loggingeventtest.cpp
deleted file mode 100644
index 8e5b7ae..0000000
--- a/src/test/cpp/spi/loggingeventtest.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (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
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <log4cxx/spi/loggingevent.h>
-#include "../util/serializationtesthelper.h"
-#include <log4cxx/logmanager.h>
-#include <log4cxx/ndc.h>
-#include <log4cxx/mdc.h>
-#include "../logunit.h"
-
-using namespace log4cxx;
-using namespace log4cxx::helpers;
-using namespace log4cxx::util;
-using namespace log4cxx::spi;
-using namespace std;
-
-
-/**
- Unit tests for LoggingEvent
- */
-LOGUNIT_CLASS(LoggingEventTest)
-{
- LOGUNIT_TEST_SUITE(LoggingEventTest);
- LOGUNIT_TEST(testSerializationSimple);
- LOGUNIT_TEST(testSerializationWithLocation);
- LOGUNIT_TEST(testSerializationNDC);
- LOGUNIT_TEST(testSerializationMDC);
- LOGUNIT_TEST_SUITE_END();
-
-public:
- void setUp()
- {
- NDC::clear();
- MDC::clear();
- }
-
- void tearDown()
- {
- LogManager::shutdown();
- }
-
-
-
-
- /**
- * Serialize a simple logging event and check it against
- * a witness.
- * @throws Exception if exception during test.
- */
- void testSerializationSimple()
- {
- LoggingEventPtr event = LoggingEventPtr(
- new LoggingEvent(
- LOG4CXX_STR("root"), Level::getInfo(), LOG4CXX_STR("Hello, world."), LocationInfo::getLocationUnavailable()));
-
- LOGUNIT_ASSERT_EQUAL(true, SerializationTestHelper::compare(
- "witness/serialization/simple.bin", event, 237));
- }
-
-
- /**
- * Serialize a logging event with an exception and check it against
- * a witness.
- * @throws Exception if exception during test.
- *
- */
- void testSerializationWithLocation()
- {
- LoggingEventPtr event = LoggingEventPtr(
- new LoggingEvent(
- LOG4CXX_STR("root"), Level::getInfo(), LOG4CXX_STR("Hello, world."), LOG4CXX_LOCATION));
-
- LOGUNIT_ASSERT_EQUAL(true, SerializationTestHelper::compare(
- "witness/serialization/location.bin", event, 237));
- }
-
- /**
- * Serialize a logging event with ndc.
- * @throws Exception if exception during test.
- *
- */
- void testSerializationNDC()
- {
- NDC::push("ndc test");
-
- LoggingEventPtr event = LoggingEventPtr(
- new LoggingEvent(
- LOG4CXX_STR("root"), Level::getInfo(), LOG4CXX_STR("Hello, world."), LocationInfo::getLocationUnavailable()));
-
- LOGUNIT_ASSERT_EQUAL(true, SerializationTestHelper::compare(
- "witness/serialization/ndc.bin", event, 237));
- }
-
- /**
- * Serialize a logging event with mdc.
- * @throws Exception if exception during test.
- *
- */
- void testSerializationMDC()
- {
- MDC::put("mdckey", "mdcvalue");
-
- LoggingEventPtr event = LoggingEventPtr(
- new LoggingEvent(
- LOG4CXX_STR("root"), Level::getInfo(), LOG4CXX_STR("Hello, world."), LocationInfo::getLocationUnavailable()));
-
- LOGUNIT_ASSERT_EQUAL(true, SerializationTestHelper::compare(
- "witness/serialization/mdc.bin", event, 237));
- }
-
-};
-
-LOGUNIT_TEST_SUITE_REGISTRATION(LoggingEventTest);
diff --git a/src/test/cpp/util/CMakeLists.txt b/src/test/cpp/util/CMakeLists.txt
index c818ab8..35cd3eb 100644
--- a/src/test/cpp/util/CMakeLists.txt
+++ b/src/test/cpp/util/CMakeLists.txt
@@ -1,6 +1,5 @@
# Components required by all tests
add_library(testingUtilities STATIC
- serializationtesthelper.cpp
absolutedateandtimefilter.cpp
absolutetimefilter.cpp
binarycompare.cpp
diff --git a/src/test/cpp/util/serializationtesthelper.cpp b/src/test/cpp/util/serializationtesthelper.cpp
deleted file mode 100644
index 903ee60..0000000
--- a/src/test/cpp/util/serializationtesthelper.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (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
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "serializationtesthelper.h"
-#include <log4cxx/helpers/bytearrayoutputstream.h>
-#include <log4cxx/helpers/objectoutputstream.h>
-#include <log4cxx/helpers/fileinputstream.h>
-#include <log4cxx/helpers/bytebuffer.h>
-#include <log4cxx/file.h>
-#include "apr_pools.h"
-
-using namespace log4cxx;
-using namespace log4cxx::util;
-using namespace log4cxx::helpers;
-using namespace log4cxx::spi;
-
-
-
-bool SerializationTestHelper::compare(
- const char* witness, const LoggingEventPtr& event, size_t endCompare)
-{
- ByteArrayOutputStreamPtr memOut = ByteArrayOutputStreamPtr( new ByteArrayOutputStream() );
- Pool p;
- ObjectOutputStream objOut(memOut, p);
- event->write(objOut, p);
- objOut.close(p);
- return compare(witness, memOut->toByteArray(), endCompare, p);
-}
-
-/**
- * Asserts the serialized form of an object.
- * @param witness file name of expected serialization.
- * @param actual byte array of actual serialization.
- * @param skip positions to skip comparison.
- * @param endCompare position to stop comparison.
- * @throws IOException thrown on IO or serialization exception.
- */
-bool SerializationTestHelper::compare(
- const char* witness, const std::vector<unsigned char>& actual,
- size_t endCompare, Pool& p)
-{
- File witnessFile(witness);
-
- char* expected = p.pstralloc(actual.size());
- FileInputStreamPtr is(new FileInputStream(witnessFile));
- ByteBuffer readBuffer(expected, actual.size());
- int bytesRead = is->read(readBuffer);
- is->close();
-
- if (bytesRead < endCompare)
- {
- puts("Witness file is shorter than expected");
- return false;
- }
-
- size_t endScan = actual.size();
-
- if (endScan > endCompare)
- {
- endScan = endCompare;
- }
-
- for (size_t i = 0; i < endScan; i++)
- {
- if (((unsigned char) expected[i]) != actual[i])
- {
- printf("Difference at offset %d, expected %x, actual %x\n", i, expected[i], actual[i]);
- return false;
- }
- }
-
- return true;
-
-}
diff --git a/src/test/cpp/util/serializationtesthelper.h b/src/test/cpp/util/serializationtesthelper.h
deleted file mode 100644
index 5d1cdcd..0000000
--- a/src/test/cpp/util/serializationtesthelper.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (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
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _LOG4CXX_TESTS_UTIL_SERIALIZATIONTESTHELPER_H
-#define _LOG4CXX_TESTS_UTIL_SERIALIZATIONTESTHELPER_H
-
-#include <log4cxx/spi/loggingevent.h>
-
-namespace log4cxx
-{
-namespace util
-{
-class SerializationTestHelper
-{
- public:
- static bool compare(const char* filename,
- const log4cxx::spi::LoggingEventPtr& event,
- size_t stopCompare);
- static bool compare(const char* filename,
- const std::vector<unsigned char>& array,
- size_t stopCompare, log4cxx::helpers::Pool& p);
- private:
- SerializationTestHelper();
- SerializationTestHelper(const SerializationTestHelper&);
- SerializationTestHelper& operator=(SerializationTestHelper&);
-};
-}
-}
-
-#endif
diff --git a/src/test/resources/witness/serialization/exception.bin b/src/test/resources/witness/serialization/exception.bin
deleted file mode 100644
index 87b0c1d..0000000
Binary files a/src/test/resources/witness/serialization/exception.bin and /dev/null differ
diff --git a/src/test/resources/witness/serialization/info.bin b/src/test/resources/witness/serialization/info.bin
deleted file mode 100644
index f887f39..0000000
Binary files a/src/test/resources/witness/serialization/info.bin and /dev/null differ
diff --git a/src/test/resources/witness/serialization/location.bin b/src/test/resources/witness/serialization/location.bin
deleted file mode 100644
index c798850..0000000
Binary files a/src/test/resources/witness/serialization/location.bin and /dev/null differ
diff --git a/src/test/resources/witness/serialization/mdc.bin b/src/test/resources/witness/serialization/mdc.bin
deleted file mode 100644
index 42e994e..0000000
Binary files a/src/test/resources/witness/serialization/mdc.bin and /dev/null differ
diff --git a/src/test/resources/witness/serialization/ndc.bin b/src/test/resources/witness/serialization/ndc.bin
deleted file mode 100644
index 7f43455..0000000
Binary files a/src/test/resources/witness/serialization/ndc.bin and /dev/null differ
diff --git a/src/test/resources/witness/serialization/simple.bin b/src/test/resources/witness/serialization/simple.bin
deleted file mode 100644
index c31f3cf..0000000
Binary files a/src/test/resources/witness/serialization/simple.bin and /dev/null differ