31 #include <boost/format.hpp> 32 #include <boost/filesystem/fstream.hpp> 34 #include "../logging/Logger.h" 35 #include "../logging/LoggerFactory.h" 50 = logging::LoggerFactory::getInstance().getLogger(
"rsc.config.configure()");
55 const boost::filesystem::path& path,
56 const istream& stream) {
57 cerr <<
" " << label <<
" " << path <<
" " 58 << (stream ?
"exists" :
"does not exist") << endl;
62 const string& configFileName,
63 const string& environmentVariablePrefix,
66 bool stripEnvironmentVariablePrefix,
67 const boost::filesystem::path& prefix) {
72 cerr <<
"Configuring with sources (lowest priority first)" << endl
73 <<
" 1. Configuration files" << endl;
78 boost::filesystem::path
81 boost::filesystem::ifstream stream(prefixWideFile);
84 prefixWideFile, stream);
90 }
catch (
const runtime_error& e) {
92 "Failed to process prefix-wide configuration file `" 93 << prefixWideFile <<
"': " << e.what());
102 bool isUserConfigDirOK =
false;
106 boost::filesystem::ifstream stream(userFile);
110 isUserConfigDirOK =
true;
115 }
catch (
const runtime_error& e) {
117 "Failed to process user-specific configuration file `" 118 << (isUserConfigDirOK
120 :
"<failed to determine user config dir>")
121 <<
"': " << e.what());
126 boost::filesystem::ifstream stream(configFileName);
129 configFileName, stream);
140 stripEnvironmentVariablePrefix);
142 cerr <<
" 2. Environment variables with prefix " 143 << environmentVariablePrefix << endl;
145 if (!matches.empty()) {
146 for (EnvironmentVariableSource::Matches::const_iterator it
147 = matches.begin(); it != matches.end(); ++it) {
149 << it->getRawName() <<
" -> " << it->getValue();
162 cerr <<
" 3. Commandline options" << endl;
166 for (
int i = 0; i < argc; ++i) {
167 cerr <<
" " << argv[i] << endl;
174 cerr <<
" <none>" << endl;
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.
path userConfigDirectory()
Return the canonical directory for configuration files of the user associated with the current proces...
void describeFileStream(const std::string &label, const boost::filesystem::path &path, const istream &stream)
Matches getMatches()
Return matching environment variables.
Objects of this class analyze the environment of the current process, finding environment variables w...
Objects of this class parse streams that contain configuration information in "ini-file" syntax...
A source for options from the command line using a -D java properties-like syntax.
void configure(OptionHandler &handler, const string &configFileName, const string &environmentVariablePrefix, int argc, const char **argv, bool stripEnvironmentVariablePrefix, const boost::filesystem::path &prefix)
Pass configuration options in from configuration files derived from configFileName and environment va...
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.
Implementations of this interface receive options from ConfigSource objects.
std::vector< Match > Matches
boost::shared_ptr< std::string > getEnvironmentVariable(const std::string &name)
Return the value of the environment value name or an empty pointer.
path prefixConfigDirectory(const path &prefix)
#define RSCWARN(logger, msg)
Provides a hierarchical logging system with the possibility to install different backends, which are instances of LoggingSystem.
void provideOptions(OptionHandler &handler)
Implementations should pass all configuration options to handler.
boost::shared_ptr< Logger > LoggerPtr