This file is an example of how to use the Qt event loop to monitor the Log4cxx configuration file.
#include "config-qt.h"
#include <QCoreApplication>
#include <QVector>
#include <QFileInfo>
#include <QDir>
namespace com { namespace foo {
void ConfigureLogging() {
static struct log4cxx_finalizer {
~log4cxx_finalizer() {
LogManager::shutdown();
}
} finaliser;
QFileInfo app{QCoreApplication::applicationFilePath()};
QString basename{app.baseName()};
QVector<QString> paths =
{ QString(".")
, app.absoluteDir().absolutePath()
};
QVector<QString> names =
{ QString(basename + ".xml")
, QString(basename + ".properties")
, QString("MyApp.properties")
, QString("log4cxx.xml")
, QString("log4cxx.properties")
, QString("log4j.xml")
, QString("log4j.properties")
};
#if defined(_DEBUG)
helpers::LogLog::setInternalDebugging(true);
#endif
auto status = spi::ConfigurationStatus::NotConfigured;
auto selectedPath = QString();
std::tie(status, selectedPath) = qt::Configuration::configureFromFileAndWatch(paths, names);
if (status == spi::ConfigurationStatus::NotConfigured)
BasicConfigurator::configure();
}
auto getLogger(
const QString& name) ->
LoggerPtr {
return name.isEmpty()
? LogManager::getRootLogger()
: LogManager::getLogger(name.toStdString());
}
auto getLogger(
const char* name) ->
LoggerPtr {
return name
? LogManager::getLogger(name)
: LogManager::getRootLogger();
}
} }
Definition: configuration.h:25
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:27