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

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


The following commit(s) were added to refs/heads/next_stable by this push:
     new f3eaedec LOGCXX-573 Give the user feedback if things are configured 
(#172)
f3eaedec is described below

commit f3eaedece37af0d2a822fb8af8ee6d806234a89e
Author: Robert Middleton <[email protected]>
AuthorDate: Mon Dec 26 13:55:20 2022 -0500

    LOGCXX-573 Give the user feedback if things are configured (#172)
    
    When configuring Log4cxx with an XML file or a properties file, feedback 
will now be given to the user to know if the configuration was successful or 
not.
---
 src/main/cpp/domconfigurator.cpp                | 70 ++++++++++++++++---------
 src/main/cpp/propertyconfigurator.cpp           | 30 +++++++----
 src/main/include/log4cxx/propertyconfigurator.h | 12 ++---
 src/main/include/log4cxx/spi/configurator.h     |  8 ++-
 src/main/include/log4cxx/xml/domconfigurator.h  | 26 ++++-----
 5 files changed, 90 insertions(+), 56 deletions(-)

diff --git a/src/main/cpp/domconfigurator.cpp b/src/main/cpp/domconfigurator.cpp
index 68b154b2..360b9bfb 100644
--- a/src/main/cpp/domconfigurator.cpp
+++ b/src/main/cpp/domconfigurator.cpp
@@ -778,7 +778,7 @@ void DOMConfigurator::setParameter(log4cxx::helpers::Pool& 
p,
        propSetter.setProperty(name, value, p);
 }
 
-void DOMConfigurator::doConfigure(const File& filename, 
spi::LoggerRepositoryPtr repository1)
+spi::ConfigurationStatus DOMConfigurator::doConfigure(const File& filename, 
spi::LoggerRepositoryPtr repository1)
 {
        repository1->setConfigured(true);
        m_priv->repository = repository1;
@@ -804,6 +804,7 @@ void DOMConfigurator::doConfigure(const File& filename, 
spi::LoggerRepositoryPtr
                msg2.append(LOG4CXX_STR("]. "));
                msg2.append(io.what());
                LogLog::error(msg2);
+               return spi::ConfigurationStatus::NotConfigured;
        }
        else
        {
@@ -835,6 +836,7 @@ void DOMConfigurator::doConfigure(const File& filename, 
spi::LoggerRepositoryPtr
                        }
 
                        LogLog::error(msg2);
+                       return spi::ConfigurationStatus::NotConfigured;
                }
                else
                {
@@ -843,66 +845,68 @@ void DOMConfigurator::doConfigure(const File& filename, 
spi::LoggerRepositoryPtr
                        parse(p, utf8Decoder, doc->root, doc, appenders);
                }
        }
+
+       return spi::ConfigurationStatus::Configured;
 }
 
-void DOMConfigurator::configure(const std::string& filename)
+spi::ConfigurationStatus DOMConfigurator::configure(const std::string& 
filename)
 {
        File file(filename);
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 }
 
 #if LOG4CXX_WCHAR_T_API
-void DOMConfigurator::configure(const std::wstring& filename)
+spi::ConfigurationStatus DOMConfigurator::configure(const std::wstring& 
filename)
 {
        File file(filename);
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 }
 #endif
 
 #if LOG4CXX_UNICHAR_API
-void DOMConfigurator::configure(const std::basic_string<UniChar>& filename)
+spi::ConfigurationStatus DOMConfigurator::configure(const 
std::basic_string<UniChar>& filename)
 {
        File file(filename);
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 }
 #endif
 
 #if LOG4CXX_CFSTRING_API
-void DOMConfigurator::configure(const CFStringRef& filename)
+spi::ConfigurationStatus DOMConfigurator::configure(const CFStringRef& 
filename)
 {
        File file(filename);
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 }
 #endif
 
 
-void DOMConfigurator::configureAndWatch(const std::string& filename)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::string& 
filename)
 {
-       configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
+       return configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
 }
 
 #if LOG4CXX_WCHAR_T_API
-void DOMConfigurator::configureAndWatch(const std::wstring& filename)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const 
std::wstring& filename)
 {
-       configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
+       return configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
 }
 #endif
 
 #if LOG4CXX_UNICHAR_API
-void DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& 
filename)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const 
std::basic_string<UniChar>& filename)
 {
-       configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
+       return configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
 }
 #endif
 
 #if LOG4CXX_CFSTRING_API
-void DOMConfigurator::configureAndWatch(const CFStringRef& filename)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const CFStringRef& 
filename)
 {
-       configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
+       return configureAndWatch(filename, FileWatchdog::DEFAULT_DELAY);
 }
 #endif
 
-void DOMConfigurator::configureAndWatch(const std::string& filename, long 
delay)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const std::string& 
filename, long delay)
 {
        File file(filename);
 #if APR_HAS_THREADS
@@ -913,17 +917,21 @@ void DOMConfigurator::configureAndWatch(const 
std::string& filename, long delay)
                delete xdog;
        }
 
+       spi::ConfigurationStatus status = DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
+
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);
        xdog->setDelay(delay);
        xdog->start();
+
+       return status;
 #else
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 #endif
 }
 
 #if LOG4CXX_WCHAR_T_API
-void DOMConfigurator::configureAndWatch(const std::wstring& filename, long 
delay)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const 
std::wstring& filename, long delay)
 {
        File file(filename);
 #if APR_HAS_THREADS
@@ -934,18 +942,22 @@ void DOMConfigurator::configureAndWatch(const 
std::wstring& filename, long delay
                delete xdog;
        }
 
+       spi::ConfigurationStatus status = DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
+
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);
        xdog->setDelay(delay);
        xdog->start();
+
+       return status;
 #else
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 #endif
 }
 #endif
 
 #if LOG4CXX_UNICHAR_API
-void DOMConfigurator::configureAndWatch(const std::basic_string<UniChar>& 
filename, long delay)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const 
std::basic_string<UniChar>& filename, long delay)
 {
        File file(filename);
 #if APR_HAS_THREADS
@@ -956,18 +968,22 @@ void DOMConfigurator::configureAndWatch(const 
std::basic_string<UniChar>& filena
                delete xdog;
        }
 
+       spi::ConfigurationStatus status = DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
+
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);
        xdog->setDelay(delay);
        xdog->start();
+
+       return status;
 #else
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 #endif
 }
 #endif
 
 #if LOG4CXX_CFSTRING_API
-void DOMConfigurator::configureAndWatch(const CFStringRef& filename, long 
delay)
+spi::ConfigurationStatus DOMConfigurator::configureAndWatch(const CFStringRef& 
filename, long delay)
 {
        File file(filename);
 #if APR_HAS_THREADS
@@ -978,12 +994,16 @@ void DOMConfigurator::configureAndWatch(const 
CFStringRef& filename, long delay)
                delete xdog;
        }
 
+       spi::ConfigurationStatus status = DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
+
        xdog = new XMLWatchdog(file);
        APRInitializer::registerCleanup(xdog);
        xdog->setDelay(delay);
        xdog->start();
+
+       return status;
 #else
-       DOMConfigurator().doConfigure(file, LogManager::getLoggerRepository());
+       return DOMConfigurator().doConfigure(file, 
LogManager::getLoggerRepository());
 #endif
 }
 #endif
diff --git a/src/main/cpp/propertyconfigurator.cpp 
b/src/main/cpp/propertyconfigurator.cpp
index 2034c310..2ece4d1a 100644
--- a/src/main/cpp/propertyconfigurator.cpp
+++ b/src/main/cpp/propertyconfigurator.cpp
@@ -89,7 +89,7 @@ PropertyConfigurator::~PropertyConfigurator()
        delete registry;
 }
 
-void PropertyConfigurator::doConfigure(const File& configFileName,
+spi::ConfigurationStatus PropertyConfigurator::doConfigure(const File& 
configFileName,
        spi::LoggerRepositoryPtr hierarchy)
 {
        hierarchy->setConfigured(true);
@@ -105,7 +105,7 @@ void PropertyConfigurator::doConfigure(const File& 
configFileName,
        {
                LogLog::error(((LogString) LOG4CXX_STR("Could not read 
configuration file ["))
                        + configFileName.getPath() + LOG4CXX_STR("].") + ": " + 
ex.what());
-               return;
+               return spi::ConfigurationStatus::NotConfigured;
        }
 
        try
@@ -113,34 +113,36 @@ void PropertyConfigurator::doConfigure(const File& 
configFileName,
                LogString debugMsg = LOG4CXX_STR("Loading configuration file [")
                                + configFileName.getPath() + LOG4CXX_STR("].");
                LogLog::debug(debugMsg);
-               doConfigure(props, hierarchy);
+               return doConfigure(props, hierarchy);
        }
        catch (const std::exception& ex)
        {
                LogLog::error(((LogString) LOG4CXX_STR("Could not parse 
configuration file ["))
                        + configFileName.getPath() + LOG4CXX_STR("]."), ex);
        }
+
+       return spi::ConfigurationStatus::NotConfigured;
 }
 
-void PropertyConfigurator::configure(const File& configFilename)
+spi::ConfigurationStatus PropertyConfigurator::configure(const File& 
configFilename)
 {
-       PropertyConfigurator().doConfigure(configFilename, 
LogManager::getLoggerRepository());
+       return PropertyConfigurator().doConfigure(configFilename, 
LogManager::getLoggerRepository());
 }
 
-void PropertyConfigurator::configure(helpers::Properties& properties)
+spi::ConfigurationStatus PropertyConfigurator::configure(helpers::Properties& 
properties)
 {
-       PropertyConfigurator().doConfigure(properties, 
LogManager::getLoggerRepository());
+       return PropertyConfigurator().doConfigure(properties, 
LogManager::getLoggerRepository());
 }
 
 #if APR_HAS_THREADS
-void PropertyConfigurator::configureAndWatch(const File& configFilename)
+spi::ConfigurationStatus PropertyConfigurator::configureAndWatch(const File& 
configFilename)
 {
-       configureAndWatch(configFilename, FileWatchdog::DEFAULT_DELAY);
+       return configureAndWatch(configFilename, FileWatchdog::DEFAULT_DELAY);
 }
 
 
 
-void PropertyConfigurator::configureAndWatch(
+spi::ConfigurationStatus PropertyConfigurator::configureAndWatch(
        const File& configFilename, long delay)
 {
        if (pdog)
@@ -149,14 +151,18 @@ void PropertyConfigurator::configureAndWatch(
                delete pdog;
        }
 
+       spi::ConfigurationStatus stat = 
PropertyConfigurator().doConfigure(configFilename, 
LogManager::getLoggerRepository());
+
        pdog = new PropertyWatchdog(configFilename);
        APRInitializer::registerCleanup(pdog);
        pdog->setDelay(delay);
        pdog->start();
+
+       return stat;
 }
 #endif
 
-void PropertyConfigurator::doConfigure(helpers::Properties& properties,
+spi::ConfigurationStatus 
PropertyConfigurator::doConfigure(helpers::Properties& properties,
        spi::LoggerRepositoryPtr hierarchy)
 {
        hierarchy->setConfigured(true);
@@ -209,6 +215,8 @@ void PropertyConfigurator::doConfigure(helpers::Properties& 
properties,
        // We don't want to hold references to appenders preventing their
        // destruction.
        registry->clear();
+
+       return spi::ConfigurationStatus::Configured;
 }
 
 void PropertyConfigurator::configureLoggerFactory(helpers::Properties& props)
diff --git a/src/main/include/log4cxx/propertyconfigurator.h 
b/src/main/include/log4cxx/propertyconfigurator.h
index 416df08a..675a69d1 100644
--- a/src/main/include/log4cxx/propertyconfigurator.h
+++ b/src/main/include/log4cxx/propertyconfigurator.h
@@ -282,13 +282,13 @@ class LOG4CXX_EXPORT PropertyConfigurator :
                configuration information is stored.
                @param hierarchy The hierarchy to operation upon.
                */
-               void doConfigure(const File& configFileName,
+               spi::ConfigurationStatus doConfigure(const File& configFileName,
                        spi::LoggerRepositoryPtr hierarchy) override;
 
                /**
                Read configuration options from file 
<code>configFilename</code>.
                */
-               static void configure(const File& configFilename);
+               static spi::ConfigurationStatus configure(const File& 
configFilename);
 
                /**
                Like {@link #configureAndWatch(const File& configFilename, long 
delay)}
@@ -297,7 +297,7 @@ class LOG4CXX_EXPORT PropertyConfigurator :
                is used.
                @param configFilename A file in key=value format.
                */
-               static void configureAndWatch(const File& configFilename);
+               static spi::ConfigurationStatus configureAndWatch(const File& 
configFilename);
 
                /**
                Read the configuration file <code>configFilename</code> if it
@@ -310,7 +310,7 @@ class LOG4CXX_EXPORT PropertyConfigurator :
                @param configFilename A file in key=value format.
                @param delay The delay in milliseconds to wait between each 
check.
                */
-               static void configureAndWatch(const File& configFilename,
+               static spi::ConfigurationStatus configureAndWatch(const File& 
configFilename,
                        long delay);
 
                /**
@@ -318,14 +318,14 @@ class LOG4CXX_EXPORT PropertyConfigurator :
                See {@link PropertyConfigurator#doConfigure doConfigure}
                for the expected format.
                */
-               static void configure(helpers::Properties& properties);
+               static spi::ConfigurationStatus configure(helpers::Properties& 
properties);
 
                /**
                Read configuration options from <code>properties</code>.
                See {@link PropertyConfigurator#doConfigure doConfigure}
                for the expected format.
                */
-               void doConfigure(helpers::Properties& properties,
+               spi::ConfigurationStatus doConfigure(helpers::Properties& 
properties,
                        spi::LoggerRepositoryPtr hierarchy);
 
                // 
--------------------------------------------------------------------------
diff --git a/src/main/include/log4cxx/spi/configurator.h 
b/src/main/include/log4cxx/spi/configurator.h
index 144d0680..68881cea 100644
--- a/src/main/include/log4cxx/spi/configurator.h
+++ b/src/main/include/log4cxx/spi/configurator.h
@@ -26,6 +26,12 @@ class File;
 
 namespace spi
 {
+
+enum class ConfigurationStatus{
+       Configured,
+       NotConfigured,
+};
+
 /**
 Implemented by classes capable of configuring log4j using a URL.
 */
@@ -43,7 +49,7 @@ class LOG4CXX_EXPORT Configurator : virtual public 
helpers::Object
                @param configFileName The file to parse
                @param repository The hierarchy to operation upon.
                */
-               virtual void doConfigure(const File& configFileName,
+               virtual ConfigurationStatus doConfigure(const File& 
configFileName,
                        spi::LoggerRepositoryPtr repository) = 0;
 
        protected:
diff --git a/src/main/include/log4cxx/xml/domconfigurator.h 
b/src/main/include/log4cxx/xml/domconfigurator.h
index 7f1bddfc..e4336c63 100644
--- a/src/main/include/log4cxx/xml/domconfigurator.h
+++ b/src/main/include/log4cxx/xml/domconfigurator.h
@@ -218,15 +218,15 @@ class LOG4CXX_EXPORT DOMConfigurator :
                /**
                A static version of #doConfigure.
                */
-               static void configure(const std::string& filename);
+               static spi::ConfigurationStatus configure(const std::string& 
filename);
 #if LOG4CXX_WCHAR_T_API
-               static void configure(const std::wstring& filename);
+               static spi::ConfigurationStatus configure(const std::wstring& 
filename);
 #endif
 #if LOG4CXX_UNICHAR_API
-               static void configure(const std::basic_string<UniChar>& 
filename);
+               static spi::ConfigurationStatus configure(const 
std::basic_string<UniChar>& filename);
 #endif
 #if LOG4CXX_CFSTRING_API
-               static void configure(const CFStringRef& filename);
+               static spi::ConfigurationStatus configure(const CFStringRef& 
filename);
 #endif
                /**
                Like #configureAndWatch(const std::string& configFilename, long 
delay)
@@ -234,15 +234,15 @@ class LOG4CXX_EXPORT DOMConfigurator :
                log4cxx::helpers::FileWatchdog#DEFAULT_DELAY is used.
                @param configFilename A log4j configuration file in XML format.
                */
-               static void configureAndWatch(const std::string& 
configFilename);
+               static spi::ConfigurationStatus configureAndWatch(const 
std::string& configFilename);
 #if LOG4CXX_WCHAR_T_API
-               static void configureAndWatch(const std::wstring& 
configFilename);
+               static spi::ConfigurationStatus configureAndWatch(const 
std::wstring& configFilename);
 #endif
 #if LOG4CXX_UNICHAR_API
-               static void configureAndWatch(const std::basic_string<UniChar>& 
configFilename);
+               static spi::ConfigurationStatus configureAndWatch(const 
std::basic_string<UniChar>& configFilename);
 #endif
 #if LOG4CXX_CFSTRING_API
-               static void configureAndWatch(const CFStringRef& 
configFilename);
+               static spi::ConfigurationStatus configureAndWatch(const 
CFStringRef& configFilename);
 #endif
                /**
                Read the configuration file <code>configFilename</code> if it
@@ -255,18 +255,18 @@ class LOG4CXX_EXPORT DOMConfigurator :
                @param configFilename A log4j configuration file in XML format.
                @param delay The delay in milliseconds to wait between each 
check.
                */
-               static void configureAndWatch(const std::string& configFilename,
+               static spi::ConfigurationStatus configureAndWatch(const 
std::string& configFilename,
                        long delay);
 #if LOG4CXX_WCHAR_T_API
-               static void configureAndWatch(const std::wstring& 
configFilename,
+               static spi::ConfigurationStatus configureAndWatch(const 
std::wstring& configFilename,
                        long delay);
 #endif
 #if LOG4CXX_UNICHAR_API
-               static void configureAndWatch(const std::basic_string<UniChar>& 
configFilename,
+               static spi::ConfigurationStatus configureAndWatch(const 
std::basic_string<UniChar>& configFilename,
                        long delay);
 #endif
 #if LOG4CXX_CFSTRING_API
-               static void configureAndWatch(const CFStringRef& configFilename,
+               static spi::ConfigurationStatus configureAndWatch(const 
CFStringRef& configFilename,
                        long delay);
 #endif
 
@@ -277,7 +277,7 @@ class LOG4CXX_EXPORT DOMConfigurator :
                @param filename The file to parse.
                @param repository The hierarchy to operation upon.
                */
-               void doConfigure(const File& filename,
+               spi::ConfigurationStatus doConfigure(const File& filename,
                        spi::LoggerRepositoryPtr repository) override;
 
        protected:

Reply via email to