src: Adding log4cxx logging
Refs: #1505
Change-Id: Ib154d91f81acf3f1dd8bbcf552062a16d03fec74
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index 7726869..b42bf80 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -3,6 +3,7 @@
#include <boost/algorithm/string.hpp>
#include <boost/property_tree/info_parser.hpp>
#include <boost/property_tree/ptree.hpp>
+#include <boost/filesystem.hpp>
#include <ndn-cxx/name.hpp>
@@ -163,6 +164,72 @@
return false;
}
+ try {
+ std::string logDir = SectionAttributeTree.get<string>("log-dir");
+ if (boost::filesystem::exists(logDir)) {
+ if (boost::filesystem::is_directory(logDir)) {
+ std::string testFileName=logDir+"/test.log";
+ ofstream testOutFile;
+ testOutFile.open(testFileName.c_str());
+ if (testOutFile.is_open() && testOutFile.good()) {
+ m_nlsr.getConfParameter().setLogDir(logDir);
+ }
+ else {
+ std::cerr << "User does not have read and write permission on the directory";
+ std::cerr << std::endl;
+ return false;
+ }
+ testOutFile.close();
+ remove(testFileName.c_str());
+ }
+ else {
+ std::cerr << "Provided path is not a directory" << std::endl;
+ return false;
+ }
+ }
+ else {
+ std::cerr << "Log directory provided does not exists" << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "You must configure log directory" << std::endl;
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
+ try {
+ std::string seqDir = SectionAttributeTree.get<string>("seq-dir");
+ if (boost::filesystem::exists(seqDir)) {
+ if (boost::filesystem::is_directory(seqDir)) {
+ std::string testFileName=seqDir+"/test.seq";
+ ofstream testOutFile;
+ testOutFile.open(testFileName.c_str());
+ if (testOutFile.is_open() && testOutFile.good()) {
+ m_nlsr.getConfParameter().setSeqFileDir(seqDir);
+ }
+ else {
+ std::cerr << "User does not have read and write permission on the directory";
+ std::cerr << std::endl;
+ return false;
+ }
+ testOutFile.close();
+ remove(testFileName.c_str());
+ }
+ else {
+ std::cerr << "Provided path is not a directory" << std::endl;
+ return false;
+ }
+ }
+ else {
+ std::cerr << "Seq directory provided does not exists" << std::endl;
+ return false;
+ }
+ }
+ catch (const std::exception& ex) {
+ std::cerr << "You must configure sequence directory" << std::endl;
+ std::cerr << ex.what() << std::endl;
+ return false;
+ }
return true;
}
@@ -233,7 +300,7 @@
m_nlsr.getAdjacencyList().insert(adj);
}
else {
- cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
+ std::cerr << " Wrong command format ! [name /nbr/name/ \n face-uri /uri\n]";
std::cerr << " or bad URI format" << std::endl;
}
}
@@ -336,8 +403,7 @@
m_nlsr.getNamePrefixList().insert(namePrefix);
}
else {
- std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI";
- std::cerr << std::endl;
+ std::cerr << " Wrong command format ! [prefix /name/prefix] or bad URI" << std::endl;
return false;
}
}