Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert to console output when configuration file is missing in examples #267

Merged
merged 3 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/examples/cpp/com/foo/config-qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -51,7 +52,11 @@ void ConfigureLogging() {
#if defined(_DEBUG)
log4cxx::helpers::LogLog::setInternalDebugging(true);
#endif
log4cxx::qt::Configuration::configureFromFileAndWatch(paths, names);
auto status = log4cxx::spi::ConfigurationStatus::NotConfigured;
auto selectedPath = QString();
std::tie(status, selectedPath) = log4cxx::qt::Configuration::configureFromFileAndWatch(paths, names);
if (status == log4cxx::spi::ConfigurationStatus::NotConfigured)
log4cxx::BasicConfigurator::configure(); // Send events to the console
}

// Retrieve the \c name logger pointer.
Expand Down
4 changes: 3 additions & 1 deletion src/examples/cpp/com/foo/config2.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "com/foo/config.h"
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>
#include <log4cxx/logmanager.h>

Expand All @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/examples/cpp/com/foo/config3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/main/include/log4cxx/basicconfigurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Loading