This file is a example of how provide application specific values for use in the configuration file and to use the current module name to select the Log4cxx configuration file.
#include "config.h"
#include "product_version.h"
#include <vector>
namespace com { namespace foo {
auto getLogger(
const std::string& name) ->
LoggerPtr {
static struct log4cxx_initializer {
log4cxx_initializer() {
auto vendorFolder = getVendorFolder();
auto productFolder = getProductFolder();
auto& props = spi::Configurator::properties();
#ifndef WIN32
props.setProperty(LOG4CXX_STR("LocalAppData"), LOG4CXX_STR("/var/local"));
#endif
props.setProperty(LOG4CXX_STR("CURRENT_VENDOR_FOLDER"), lsVendorFolder);
props.setProperty(LOG4CXX_STR("CURRENT_PRODUCT_FOLDER"), lsProductFolder);
DefaultConfigurator::setConfigurationWatchSeconds(5);
std::vector<LogString> paths
{ LOG4CXX_STR(".")
, LOG4CXX_STR("${PROGRAM_FILE_PATH.PARENT_PATH}")
};
std::vector<LogString> names
{ LOG4CXX_STR("${PROGRAM_FILE_PATH.STEM}.xml")
, LOG4CXX_STR("${PROGRAM_FILE_PATH.STEM}.properties")
};
auto status = spi::ConfigurationStatus::NotConfigured;
std::tie(status, selectedPath) = DefaultConfigurator::configureFromFile(paths, names);
if (status == spi::ConfigurationStatus::NotConfigured)
BasicConfigurator::configure();
}
~log4cxx_initializer() {
LogManager::shutdown();
}
} initialiser;
return name.empty()
? LogManager::getRootLogger()
: LogManager::getLogger(name);
}
} }
#define LOG4CXX_DECODE_CHAR(var, src)
Create a log4cxx::LogString equivalent of src.
Definition: log4cxx/helpers/transcoder.h:243
Definition: appender.h:27
std::basic_string< logchar > LogString
Definition: logstring.h:60
std::shared_ptr< Logger > LoggerPtr
Definition: defaultloggerfactory.h:26