Skip to content
Snippets Groups Projects
Unverified Commit 24e86901 authored by Simon Heybrock's avatar Simon Heybrock Committed by GitHub
Browse files

Merge pull request #23147 from mantidproject/ConfigService_loading

ConfigService loading
parents b83fae2f 304c2c60
No related branches found
No related tags found
No related merge requests found
...@@ -325,6 +325,48 @@ void ConfigServiceImpl::setBaseDirectory() { ...@@ -325,6 +325,48 @@ void ConfigServiceImpl::setBaseDirectory() {
#endif #endif
} }
namespace {
// look for specific keys and throw an exception if one is found
std::string checkForBadConfigOptions(const std::string &filename,
const std::string &propertiesString) {
std::stringstream stream(propertiesString);
std::stringstream resultPropertiesString;
std::string line;
int line_num = 0;
while (std::getline(stream, line)) {
line_num += 1; // increment early
bool is_ok = true;
// Check for common errors. Empty lines are ok, things that are a key
// without a value are a critical failure. Forbidden keys are just commented
// out.
if (line.empty() || (Kernel::Strings::strip(line)[0] == '#')) {
// do nothing
} else if (line.find("FilterChannel") != std::string::npos) {
is_ok = false;
}
// Print warning to error channel and comment out offending line
if (!is_ok) {
const auto end = line.find("=");
std::cerr << "Encontered invalid key \"";
if (end != std::string::npos) {
std::cerr << Kernel::Strings::strip(line.substr(0, end));
} else {
std::cerr << Kernel::Strings::strip(line);
}
std::cerr << "\" in " << filename << " on line " << line_num << std::endl;
// comment out the property
resultPropertiesString << '#';
}
// copy over the line
resultPropertiesString << line << '\n';
}
return resultPropertiesString.str();
}
} // end of anonymous namespace
/** Loads the config file provided. /** Loads the config file provided.
* If the file contains logging setup instructions then these will be used to * If the file contains logging setup instructions then these will be used to
*setup the logging framework. *setup the logging framework.
...@@ -358,6 +400,9 @@ void ConfigServiceImpl::loadConfig(const std::string &filename, ...@@ -358,6 +400,9 @@ void ConfigServiceImpl::loadConfig(const std::string &filename,
} }
} }
// verify the contents and comment out offending lines
temp = checkForBadConfigOptions(filename, temp);
// store the property string // store the property string
if ((append) && (!m_PropertyString.empty())) { if ((append) && (!m_PropertyString.empty())) {
m_PropertyString = m_PropertyString + "\n" + temp; m_PropertyString = m_PropertyString + "\n" + temp;
......
...@@ -483,6 +483,7 @@ public: ...@@ -483,6 +483,7 @@ public:
writer << "\n"; writer << "\n";
writer << "mantid.thorax = 10\n"; writer << "mantid.thorax = 10\n";
writer << "# This comment line\n"; writer << "# This comment line\n";
writer << " # This is an indented comment line\n";
writer << "key.withnospace=5\n"; writer << "key.withnospace=5\n";
writer << "key.withnovalue"; writer << "key.withnovalue";
writer.close(); writer.close();
...@@ -512,11 +513,12 @@ public: ...@@ -512,11 +513,12 @@ public:
} }
reader.close(); reader.close();
TS_ASSERT_EQUALS(prop_lines.size(), 4); TS_ASSERT_EQUALS(prop_lines.size(), 5);
TS_ASSERT_EQUALS(prop_lines[0], "mantid.legs=6"); TS_ASSERT_EQUALS(prop_lines[0], "mantid.legs=6");
TS_ASSERT_EQUALS(prop_lines[1], ""); TS_ASSERT_EQUALS(prop_lines[1], "");
TS_ASSERT_EQUALS(prop_lines[2], "# This comment line"); TS_ASSERT_EQUALS(prop_lines[2], "# This comment line");
TS_ASSERT_EQUALS(prop_lines[3], "key.withnospace=5"); TS_ASSERT_EQUALS(prop_lines[3], " # This is an indented comment line");
TS_ASSERT_EQUALS(prop_lines[4], "key.withnospace=5");
// Clean up // Clean up
prop_file.remove(); prop_file.remove();
......
...@@ -12,10 +12,10 @@ Framework Changes ...@@ -12,10 +12,10 @@ Framework Changes
Logging Logging
------- -------
- We have changed the logging in Mantid to stop writing the a high level version of the log to a file. This had been causing numerous problems including inconsistent behaviour with multiple instances of Mantid, performance problems when logging at detailed levels, and excessive network usage in some scenarios. This does not change the rest of the logging that you see in the message display in Mantidplot or the console window. - We have changed the logging in Mantid to stop writing the a high level version of the log to a file. This had been causing numerous problems including inconsistent behaviour with multiple instances of Mantid, performance problems when logging at detailed levels, and excessive network usage in some scenarios. This does not change the rest of the logging that you see in the message display in Mantidplot or the console window. A warning message will appear if configuration for the removed componets of logging is found.
- Associated with this we have also simplified the python methods used to control logging. - Associated with this we have also simplified the python methods used to control logging.
.. code-block:: python .. code-block:: python
# The two methods # The two methods
......
...@@ -430,17 +430,10 @@ class MantidConfigDirectInelastic(object): ...@@ -430,17 +430,10 @@ class MantidConfigDirectInelastic(object):
"##\n" "##\n"
"\n" "\n"
"## Uncomment to change logging level\n" "## Uncomment to change logging level\n"
"## Default is information\n" "## Default is notice\n"
"## Valid values are: error, warning, notice, information, debug\n" "## Valid values are: error, warning, notice, information, debug\n"
"#logging.loggers.root.level=information\n" "#logging.loggers.root.level=information\n"
"\n" "\n"
"## Sets the lowest level messages to be logged to file\n"
"## Default is warning\n"
"## Valid values are: error, warning, notice, information, debug\n"
"#logging.channels.fileFilterChannel.level=debug\n"
"## Sets the file to write logs to\n"
"#logging.channels.fileChannel.path=../mantid.log\n"
"##\n"
"## MantidPlot\n" "## MantidPlot\n"
"##\n" "##\n"
"## Show invisible workspaces\n" "## Show invisible workspaces\n"
......
# This file can be used to override any properties for this installation. # This file can be used to override any properties for this installation.
# Any properties found in this file will override any that are found in the Mantid.Properties file # Any properties found in this file will override any that are found in the Mantid.Properties file
# As this file will not be replaced with futher installations of Mantid it is a safe place to put # As this file will not be replaced with futher installations of Mantid it is a safe place to put
# properties that suit your particular installation. # properties that suit your particular installation.
# #
# See here for a list of possible options: # See here for a list of possible options:
...@@ -56,18 +56,10 @@ Q.convention = Inelastic ...@@ -56,18 +56,10 @@ Q.convention = Inelastic
## ##
## Uncomment to change logging level ## Uncomment to change logging level
## Default is information ## Default is notice
## Valid values are: error, warning, notice, information, debug ## Valid values are: error, warning, notice, information, debug
#logging.loggers.root.level=information #logging.loggers.root.level=information
## Sets the lowest level messages to be logged to file
## Default is warning
## Valid values are: error, warning, notice, information, debug
#logging.channels.fileFilterChannel.level=debug
## Sets the file to write logs to
#logging.channels.fileChannel.path=../mantid.log
## ##
## MantidPlot ## MantidPlot
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment