Move the setting of the hierarchy
diff --git a/src/main/cpp/hierarchy.cpp b/src/main/cpp/hierarchy.cpp
index 42edf49..98e094c 100644
--- a/src/main/cpp/hierarchy.cpp
+++ b/src/main/cpp/hierarchy.cpp
@@ -53,7 +53,6 @@
{
std::unique_lock<std::mutex> lock(mutex);
root = LoggerPtr(new RootLogger(pool, Level::getDebug()));
- root->setHierarchy(weak_from_this());
defaultFactory = LoggerFactoryPtr(new DefaultLoggerFactory());
emittedNoAppenderWarning = false;
configured = false;
@@ -214,6 +213,13 @@
{
std::unique_lock<std::mutex> lock(mutex);
+ // 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(weak_from_this());
+ }
+
LoggerMap::iterator it = loggers->find(name);
if (it != loggers->end())