diff --git a/Code/Mantid/Kernel/inc/ConfigSvc.h b/Code/Mantid/Kernel/inc/ConfigSvc.h index d289efdac5f7b485014a53a443e0028195e87fdd..6cab1fc92c2f67e3137a6581dad9d2749ede53cd 100644 --- a/Code/Mantid/Kernel/inc/ConfigSvc.h +++ b/Code/Mantid/Kernel/inc/ConfigSvc.h @@ -61,7 +61,7 @@ namespace Mantid } template<typename Field> - WrappedObject(const Field& F) : T(F) + WrappedObject(Field& F) : T(F) { m_pPtr = static_cast<T*>(this); } diff --git a/Code/Mantid/Kernel/inc/Logger.h b/Code/Mantid/Kernel/inc/Logger.h index c0b18ab1bd216523f7df9d74d76c20b00ce558df..f2ec6c21c4c327340c571e02e9d64ffaa3cd3757 100755 --- a/Code/Mantid/Kernel/inc/Logger.h +++ b/Code/Mantid/Kernel/inc/Logger.h @@ -54,7 +54,7 @@ namespace Mantid PRIO_ERROR = 3, /// An error. An operation did not complete successfully, but the application as a whole is not affected. PRIO_WARNING = 4, /// A warning. An operation completed with an unexpected result. PRIO_INFORMATION = 6, /// An informational message, usually denoting the successful completion of an operation. - PRIO_DEBUG = 7 /// A debugging message.This is the lowest priority. + PRIO_DEBUG = 7 /// A debugging message.This is the lowest priority. }; /// If the Logger's log level is at least PRIO_FATAL, diff --git a/Code/Mantid/Kernel/src/ConfigSvc.cpp b/Code/Mantid/Kernel/src/ConfigSvc.cpp index 8d64c5741065d54fdc206ec40112537b04e6c4d1..85727665ac3331ff41b8ed93edb19f33fe60110b 100644 --- a/Code/Mantid/Kernel/src/ConfigSvc.cpp +++ b/Code/Mantid/Kernel/src/ConfigSvc.cpp @@ -2,6 +2,9 @@ #include "Poco/Util/LoggingConfigurator.h" #include "Poco/Util/SystemConfiguration.h" #include "Poco/Util/PropertyFileConfiguration.h" +#include <sstream> +#include <iostream> +#include <string> namespace Mantid { @@ -15,6 +18,9 @@ namespace Mantid m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>; m_pConf = 0; + + //attempt to load the default properties filename + loadConfig("Mantid.Properties"); } //destructor @@ -28,11 +34,45 @@ namespace Mantid void ConfigSvc::loadConfig(const std::string& filename) { delete m_pConf; - m_pConf = new WrappedObject<Poco::Util::PropertyFileConfiguration>(filename); - //configure the logging framework - Poco::Util::LoggingConfigurator configurator; - configurator.configure(m_pConf); + try + { + m_pConf = new WrappedObject<Poco::Util::PropertyFileConfiguration>(filename); + } + catch (std::exception e) + { + //there was a problem loading the file - it probably is not there + std::cerr << "Problem loading the logging file " << filename << " " << e.what(); + + std::string propFile = + "logging.loggers.root.level = debug\n" + "logging.loggers.root.channel.class = SplitterChannel\n" + "logging.loggers.root.channel.channel1 = consoleChannel\n" + "logging.loggers.root.channel.channel2 = fileChannel\n" + "logging.channels.consoleChannel.class = ConsoleChannel\n" + "logging.channels.consoleChannel.formatter = f1\n" + "logging.channels.fileChannel.class = FileChannel\n" + "logging.channels.fileChannel.path = sample.log\n" + "logging.channels.fileChannel.formatter.class = PatternFormatter\n" + "logging.channels.fileChannel.formatter.pattern = %s: {%p} %t\n" + "logging.formatters.f1.class = PatternFormatter\n" + "logging.formatters.f1.pattern = %s-[%p] %t\n" + "logging.formatters.f1.times = UTC\n"; + + std::istringstream istr(propFile); + m_pConf = new WrappedObject<Poco::Util::PropertyFileConfiguration>(istr); + } + + try + { + //configure the logging framework + Poco::Util::LoggingConfigurator configurator; + configurator.configure(m_pConf); + } + catch (std::exception e) + { + std::cerr << "Trouble configuring the logging framework " << e.what(); + } } std::string ConfigSvc::getString(const std::string& keyName) @@ -70,7 +110,7 @@ namespace Mantid return m_pSysConfig->getString("system.nodeName"); } -/* Removed as the use of these throughs a debug assertion about an invlid heap pointer +/* Removed as the use of these throughs a debug assertion about an invalid heap pointer File dbgheap.c Expression _CrtIsValidHeapPointer(pUserData) diff --git a/Code/Mantid/Kernel/src/Logger.cpp b/Code/Mantid/Kernel/src/Logger.cpp index 4e1206af81b8c073bb119e5011dd72be28416667..d37e6a01617e701e9aaf4118a46c578130c37538 100755 --- a/Code/Mantid/Kernel/src/Logger.cpp +++ b/Code/Mantid/Kernel/src/Logger.cpp @@ -1,6 +1,7 @@ #include "../inc/Logger.h" #include <Poco/Logger.h> #include <Poco/Message.h> +#include <iostream> namespace Mantid { @@ -11,48 +12,121 @@ namespace Mantid void Logger::fatal(const std::string& msg) { - _log.fatal(msg); + try + { + _log.fatal(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::critical(const std::string& msg) { - _log.critical(msg); + try + { + _log.critical(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::error(const std::string& msg) { - _log.error(msg); + try + { + _log.error(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } + } void Logger::warning(const std::string& msg) { - _log.warning(msg); + try + { + _log.warning(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::information(const std::string& msg) { - _log.information(msg); + try + { + _log.information(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::debug(const std::string& msg) { - _log.debug(msg); + try + { + _log.debug(msg); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::dump(const std::string& msg, const void* buffer, std::size_t length) { - _log.dump(msg,buffer,length); + try + { + _log.dump(msg,buffer,length); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } bool Logger::is(int level) const { - return _log.is(level); + try + { + return _log.is(level); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } void Logger::shutdown() { - Poco::Logger::shutdown(); + try + { + Poco::Logger::shutdown(); + } + catch (std::exception e) + { + //failures in logging are not allowed to throw exceptions out of the logging class + std::cerr << e.what(); + } } Logger& Logger::get(const std::string& name) diff --git a/Code/Mantid/Kernel/test/Mantid.properties b/Code/Mantid/Kernel/test/Mantid.properties new file mode 100644 index 0000000000000000000000000000000000000000..400867a5324241485d474750b6c7a3e3c58c65d3 --- /dev/null +++ b/Code/Mantid/Kernel/test/Mantid.properties @@ -0,0 +1,10 @@ +#framework configuration +mantid.legs = 6 + +#logging configuartion +logging.loggers.root.level = information +logging.loggers.root.channel = fileChannel +logging.channels.fileChannel.class = FileChannel +logging.channels.fileChannel.path = sample.log +logging.channels.fileChannel.formatter.class = PatternFormatter +logging.channels.fileChannel.formatter.pattern = %s: {%p} %t