Newer
Older
#include "../inc/ConfigSvc.h"
#include "Poco/Util/LoggingConfigurator.h"
#include "Poco/Util/SystemConfiguration.h"
#include "Poco/Util/PropertyFileConfiguration.h"
Nick Draper
committed
#include <sstream>
#include <iostream>
#include <string>
namespace Mantid
{
// Initialise the instance pointer to zero
ConfigSvc* ConfigSvc::m_instance=0;
//private constructor
ConfigSvc::ConfigSvc()
{
//getting at system details
m_pSysConfig = new WrappedObject<Poco::Util::SystemConfiguration>;
m_pConf = 0;
Nick Draper
committed
//attempt to load the default properties filename
loadConfig("Mantid.Properties");
}
//destructor
ConfigSvc::~ConfigSvc()
{
delete m_pSysConfig;
delete m_pConf;
}
void ConfigSvc::loadConfig(const std::string& filename)
{
delete m_pConf;
Nick Draper
committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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();
}
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
}
std::string ConfigSvc::getString(const std::string& keyName)
{
return m_pConf->getString(keyName);
}
int ConfigSvc::getInt(const std::string& keyName)
{
return 1;
}
double ConfigSvc::getDouble(const std::string& keyName)
{
return 1.0;
}
std::string ConfigSvc::getEnvironment(const std::string& keyName)
{
return m_pSysConfig->getString("system.env." + keyName);
}
std::string ConfigSvc::getOSName()
{
return m_pSysConfig->getString("system.osName");
}
std::string ConfigSvc::getOSArchitecture()
{
return m_pSysConfig->getString("system.osArchitecture");
}
std::string ConfigSvc::getComputerName()
{
return m_pSysConfig->getString("system.nodeName");
}
Nick Draper
committed
/* Removed as the use of these throughs a debug assertion about an invalid heap pointer
File dbgheap.c
Expression _CrtIsValidHeapPointer(pUserData)
std::string ConfigSvc::getOSVersion()
{
return m_pSysConfig->getString("system.osVersion");
}
std::string ConfigSvc::getCurrentDir()
{
return m_pSysConfig->getString("system.currentDir");
}
std::string ConfigSvc::getHomeDir()
{
return m_pSysConfig->getString("system.homeDir");
}
std::string ConfigSvc::getTempDir()
{
return m_pSysConfig->getString("system.tempDir");
}
*/