diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp index 3f3e19c8fe967ddf1a50ace0d1cbc68c75d4ee64..331a69cee57bd35cbd28f2d0c1247691257fae88 100644 --- a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp +++ b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp @@ -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 diff --git a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h index f90d15c74eb30c21171b934f9ac138013d0064cf..ad28bcd64db5be5eea483c0ade5a2729c5bd38bc 100644 --- a/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h +++ b/Code/Mantid/Framework/Kernel/test/ConfigServiceTest.h @@ -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: