Skip to content

Commit e1537a6

Browse files
authored
Merge pull request #816 from UWB-Biocomputing/PatilDevelopment
[ISSUE 386] Check for local log4cplus file in Home Directory.
2 parents 004f58c + de7c930 commit e1537a6

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

Simulator/Core/Graphitti_Main.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,35 @@
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+
2831
using 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

Comments
 (0)