2222#include " log4cplus/configurator.h"
2323#include " log4cplus/logger.h"
2424#include " log4cplus/loggingmacros.h"
25+ #include < cstdlib>
2526#include < fstream>
2627#include < iostream>
2728#include < string>
29+ #include < unistd.h>
30+
2831using namespace std ;
2932
33+ // Function to check whether there is a file given at a specific path
34+ bool findFile (string path)
35+ {
36+ // Opens the file at specified path
37+ ifstream newFile (path);
38+
39+ // Checks if file is opened properly, otherwise results in an error and returns false
40+ if (newFile.is_open ()) {
41+ // Use good() to check if the file exists
42+ bool found = newFile.good ();
43+ newFile.close ();
44+ return found;
45+
46+ } else {
47+ cerr << " ERROR opening file." << endl;
48+ }
49+
50+ return false ;
51+ }
52+
53+
3054// / Main function calls the Core's runSimulation method which
3155// / handles command line arguments and running the simulation.
3256// /
@@ -42,7 +66,18 @@ int main(int argc, char *argv[])
4266
4367 // Initialize log4cplus and set properties based on configure file
4468 ::log4cplus::initialize ();
45- ::log4cplus::PropertyConfigurator::doConfigure (" RuntimeFiles/log4cplus_configure.ini" );
69+
70+ // This is to find the absolute path of the home directory log4cplus file
71+ string absPath = getenv (" HOME" );
72+ absPath = absPath + " /log4cplus_configure.ini" ;
73+
74+ // Checks whether the file is in the home directory
75+ // otherwise uses the file in RuntimeFiles
76+ if (findFile (absPath)) {
77+ ::log4cplus::PropertyConfigurator::doConfigure (absPath);
78+ } else {
79+ ::log4cplus::PropertyConfigurator::doConfigure (" RuntimeFiles/log4cplus_configure.ini" );
80+ }
4681
4782 // storing command line arguments as string
4883 // required to pass as an argument to setupSimulation
0 commit comments