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 2022/11/04 13:46:52 UTC

[logging-log4cxx] branch LOGCXX-557 created (now 9b84258d)

This is an automated email from the ASF dual-hosted git repository.

rmiddleton pushed a change to branch LOGCXX-557
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at 9b84258d Keep track of appender even if not used

This branch includes the following new commits:

     new 9b84258d Keep track of appender even if not used

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[logging-log4cxx] 01/01: Keep track of appender even if not used

Posted by rm...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rmiddleton pushed a commit to branch LOGCXX-557
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit 9b84258d946b60f33d45bd69bf53c36893f831c3
Author: Robert Middleton <ro...@rm5248.com>
AuthorDate: Fri Nov 4 09:46:39 2022 -0400

    Keep track of appender even if not used
---
 src/main/cpp/fallbackerrorhandler.cpp | 11 +++++++++++
 src/main/cpp/hierarchy.cpp            | 11 +++++++++++
 src/main/include/log4cxx/hierarchy.h  |  4 ++++
 3 files changed, 26 insertions(+)

diff --git a/src/main/cpp/fallbackerrorhandler.cpp b/src/main/cpp/fallbackerrorhandler.cpp
index 91b6dddd..df650d0a 100644
--- a/src/main/cpp/fallbackerrorhandler.cpp
+++ b/src/main/cpp/fallbackerrorhandler.cpp
@@ -22,6 +22,8 @@
 #include <log4cxx/helpers/loglog.h>
 #include <log4cxx/helpers/stringhelper.h>
 #include <log4cxx/spi/loggingevent.h>
+#include <log4cxx/hierarchy.h>
+#include <log4cxx/logmanager.h>
 
 using namespace log4cxx;
 using namespace log4cxx::helpers;
@@ -103,6 +105,15 @@ void FallbackErrorHandler::setBackupAppender(const AppenderPtr& backup1)
 	LogLog::debug(((LogString) LOG4CXX_STR("FB: Setting backup appender to ["))
 		+ backup1->getName() + LOG4CXX_STR("]."));
 	m_priv->backup = backup1;
+
+	// Make sure that we keep a reference to the appender around, since otherwise
+	// the appender would be lost if it has no loggers that use it.
+	LoggerRepository* repository = LogManager::getRootLogger()->getLoggerRepository();
+	Hierarchy* hierarchy = dynamic_cast<Hierarchy*>(repository);
+	if(hierarchy){
+		hierarchy->addAppender(backup1);
+	}
+
 }
 
 void FallbackErrorHandler::activateOptions(Pool&)
diff --git a/src/main/cpp/hierarchy.cpp b/src/main/cpp/hierarchy.cpp
index b8c0c0a9..98c4ba6c 100644
--- a/src/main/cpp/hierarchy.cpp
+++ b/src/main/cpp/hierarchy.cpp
@@ -70,6 +70,7 @@ struct Hierarchy::HierarchyPrivate
 	LoggerMap loggers;
 	ProvisionNodeMap provisionNodes;
 
+	std::vector<AppenderPtr> allAppenders;
 };
 
 IMPLEMENT_LOG4CXX_OBJECT(Hierarchy)
@@ -469,3 +470,13 @@ HierarchyPtr Hierarchy::create()
 	HierarchyPtr ret(new Hierarchy);
 	return ret;
 }
+
+void Hierarchy::clearAppenders()
+{
+	m_priv->allAppenders.clear();
+}
+
+void Hierarchy::addAppender(AppenderPtr appender)
+{
+	m_priv->allAppenders.push_back(appender);
+}
diff --git a/src/main/include/log4cxx/hierarchy.h b/src/main/include/log4cxx/hierarchy.h
index 058dfdfe..153e2e62 100644
--- a/src/main/include/log4cxx/hierarchy.h
+++ b/src/main/include/log4cxx/hierarchy.h
@@ -219,6 +219,10 @@ class LOG4CXX_EXPORT Hierarchy :
 		*/
 		void updateChildren(const Logger* parent);
 
+		void clearAppenders();
+
+		void addAppender(AppenderPtr appender);
+
 	private:
 
 		/**