This file is a simpler example of how 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();
#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);
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")
};
}
~log4cxx_initializer() {
}
} initialiser;
return name.empty()
}
} }
static void configure(const LayoutPtr &layout=LayoutPtr())
Add a ConsoleAppender to the root logger that formats output using layout.
static void setConfigurationWatchSeconds(int seconds)
Make seconds the time a background thread will delay before checking for a change to the configuratio...
static std::tuple< spi::ConfigurationStatus, LogString > configureFromFile(const std::vector< LogString > &directories, const std::vector< LogString > &filenames)
Call configure() passing the default repository after calling setConfigurationFileName() with a path ...
static LoggerPtr getRootLogger()
Retrieve the root logger from the LoggerRepository.
static LoggerPtr getLogger(const std::string &name)
Retrieve the name Logger instance from the LoggerRepository using the default factory to create it if...
static void shutdown()
Safely close and remove all appenders in all loggers including the root logger.
static helpers::Properties & properties()
The key value pairs used when expanding ${varname} instances in a configuration file.
#define LOG4CXX_DECODE_CHAR(var, src)
Create a log4cxx::LogString equivalent of src.
Definition log4cxx/helpers/transcoder.h:243
@ NotConfigured
Definition configurator.h:33
Definition configuration.h:25
std::basic_string< logchar > LogString
Definition logstring.h:60