Skip to content
Snippets Groups Projects
Commit ad63fd08 authored by Janik Zikovsky's avatar Janik Zikovsky
Browse files

Refs #2584: Adding the use of a MANTIDLOGPATH variable to override the log...

Refs #2584: Adding the use of a MANTIDLOGPATH variable to override the log file path at run-time; test.
parent eeacef61
No related branches found
No related tags found
No related merge requests found
......@@ -293,6 +293,10 @@ void ConfigServiceImpl::configureLogging()
//Ensure that the logging directory exists
m_logFilePath = getString("logging.channels.fileChannel.path");
// Look in the environment for a variable to override where the log file ends up.
if (Poco::Environment::has("MANTIDLOGPATH"))
m_logFilePath = Poco::Environment::get("MANTIDLOGPATH");
Poco::Path logpath(m_logFilePath);
// An absolute path makes things simpler
......
......@@ -13,6 +13,8 @@
#include <fstream>
#include <Poco/NObserver.h>
#include <Poco/Environment.h>
#include <Poco/File.h>
using namespace Mantid::Kernel;
using Mantid::TestChannel;
......@@ -281,6 +283,26 @@ public:
settings.setString("default.facility", "ISIS");
}
/** If you set MANTIDLOGPATH environment then you change where the log ends up */
void testOverrideLogFile()
{
// Remove the file
if (Poco::File("ConfigServiceTest.log").exists())
Poco::File("ConfigServiceTest.log").remove();
TS_ASSERT(!Poco::File("ConfigServiceTest.log").exists());
Poco::Environment::set("MANTIDLOGPATH", "ConfigServiceTest.log");
const std::string propfile = getDirectoryOfExecutable() + "MantidTest.properties";
ConfigService::Instance().updateConfig(propfile);
Logger & log1 = Logger::get("logTest1");
log1.warning() << "ConfigServiceTest.testOverrideLogFile test output" << std::endl;
// The file was written?
TS_ASSERT(Poco::File("ConfigServiceTest.log").exists());
// Clean up
if (Poco::File("ConfigServiceTest.log").exists())
Poco::File("ConfigServiceTest.log").remove();
}
protected:
......
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