From ad63fd0826fa2463b4328cf358c66c2c75a8fb59 Mon Sep 17 00:00:00 2001 From: Janik Zikovsky <zikovskyjl@ornl.gov> Date: Fri, 4 Mar 2011 23:09:14 +0000 Subject: [PATCH] Refs #2584: Adding the use of a MANTIDLOGPATH variable to override the log file path at run-time; test. --- .../Framework/Kernel/src/ConfigService.cpp | 4 ++++ .../Framework/Kernel/test/ConfigServiceTest.h | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Code/Mantid/Framework/Kernel/src/ConfigService.cpp b/Code/Mantid/Framework/Kernel/src/ConfigService.cpp index 3f3e19c8fe9..331a69cee57 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 f90d15c74eb..ad28bcd64db 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: -- GitLab