You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/09/12 07:49:23 UTC

[logging-log4cxx] branch documentation_improvement created (now 27546ece)

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

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


      at 27546ece Revert to console output when configuration file is missing in documented configuration examples

This branch includes the following new commits:

     new 27546ece Revert to console output when configuration file is missing in documented configuration examples

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: Revert to console output when configuration file is missing in documented configuration examples

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

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

commit 27546ececd0ee4e8712bc50ee6e97185ebf73da1
Author: Stephen Webb <sw...@gmail.com>
AuthorDate: Tue Sep 12 17:48:50 2023 +1000

    Revert to console output when configuration file is missing in documented configuration examples
---
 src/examples/cpp/com/foo/config-qt.cpp       | 4 +++-
 src/examples/cpp/com/foo/config2.cpp         | 4 +++-
 src/examples/cpp/com/foo/config3.cpp         | 5 ++++-
 src/main/include/log4cxx/basicconfigurator.h | 9 +++++----
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/examples/cpp/com/foo/config-qt.cpp b/src/examples/cpp/com/foo/config-qt.cpp
index 64889087..41d5eca1 100644
--- a/src/examples/cpp/com/foo/config-qt.cpp
+++ b/src/examples/cpp/com/foo/config-qt.cpp
@@ -15,6 +15,7 @@
  * limitations under the License.
  */
 #include "config-qt.h"
+#include <log4cxx/basicconfigurator.h>
 #include <log4cxx/logmanager.h>
 #include <log4cxx-qt/configuration.h>
 #include <log4cxx/helpers/loglog.h>
@@ -51,7 +52,8 @@ void ConfigureLogging() {
 #if defined(_DEBUG)
 	log4cxx::helpers::LogLog::setInternalDebugging(true);
 #endif
-	log4cxx::qt::Configuration::configureFromFileAndWatch(paths, names);
+	if (log4cxx::qt::Configuration::configureFromFileAndWatch(paths, names) == log4cxx::spi::ConfigurationStatus::NotConfigured)
+		log4cxx::BasicConfigurator::configure(); // Send events to the console
 }
 
 // Retrieve the \c name logger pointer.
diff --git a/src/examples/cpp/com/foo/config2.cpp b/src/examples/cpp/com/foo/config2.cpp
index 2c25f8af..8228e374 100644
--- a/src/examples/cpp/com/foo/config2.cpp
+++ b/src/examples/cpp/com/foo/config2.cpp
@@ -1,4 +1,5 @@
 #include "com/foo/config.h"
+#include <log4cxx/basicconfigurator.h>
 #include <log4cxx/propertyconfigurator.h>
 #include <log4cxx/logmanager.h>
 
@@ -7,7 +8,8 @@ namespace com { namespace foo {
 auto getLogger(const std::string& name) -> LoggerPtr {
 	static struct log4cxx_initializer {
 		log4cxx_initializer() {
-			log4cxx::PropertyConfigurator::configure("MyApp.properties");
+			if (log4cxx::PropertyConfigurator::configure("MyApp.properties") == log4cxx::spi::ConfigurationStatus::NotConfigured)
+				log4cxx::BasicConfigurator::configure(); // Send events to the console
 		}
 		~log4cxx_initializer() {
 			log4cxx::LogManager::shutdown();
diff --git a/src/examples/cpp/com/foo/config3.cpp b/src/examples/cpp/com/foo/config3.cpp
index d38ae43c..34974051 100644
--- a/src/examples/cpp/com/foo/config3.cpp
+++ b/src/examples/cpp/com/foo/config3.cpp
@@ -17,6 +17,7 @@
 #include "config.h"
 #include <log4cxx/logmanager.h>
 #include <log4cxx/logstring.h>
+#include <log4cxx/basicconfigurator.h>
 #include <log4cxx/defaultconfigurator.h>
 #include <log4cxx/helpers/pool.h>
 #include <log4cxx/file.h>
@@ -136,8 +137,10 @@ void SelectConfigurationFile() {
 			}
 		}
 		if (extension[i]) // Found a configuration file?
-			break;
+			return;
 	}
+	// Configuration file not found - send events to the console
+	BasicConfigurator::configure();
 }
 
 } // namespace
diff --git a/src/main/include/log4cxx/basicconfigurator.h b/src/main/include/log4cxx/basicconfigurator.h
index 59bf032d..edecfade 100644
--- a/src/main/include/log4cxx/basicconfigurator.h
+++ b/src/main/include/log4cxx/basicconfigurator.h
@@ -29,10 +29,11 @@ class Appender;
 typedef std::shared_ptr<Appender> AppenderPtr;
 
 /**
-Use this class to quickly configure the package.
-<p>For file based configuration see
-PropertyConfigurator. For XML based configuration see
-DOMConfigurator.
+Use BasicConfigurator (static) methods to configure Log4cxx
+when not using a configuration file.
+
+For <code>key=value</code> format configuration see PropertyConfigurator.
+For XML format configuration see xml::DOMConfigurator.
 */
 class LOG4CXX_EXPORT BasicConfigurator
 {