Commit 78d84cb6 authored by Mohcine Chraibi's avatar Mohcine Chraibi

add git logging to jpscore

parent 9fd03ad6
This diff is collapsed.
......@@ -45,6 +45,41 @@
#include "../routing/ai_router/AIRouter.h"
#include "../routing/ff_router/ffRouter.h"
/* https://stackoverflow.com/questions/38530981/output-compiler-version-in-a-c-program#38531037 */
std::string ver_string(int a, int b, int c) {
std::ostringstream ss;
ss << a << '.' << b << '.' << c;
return ss.str();
}
//https://sourceforge.net/p/predef/wiki/Compilers/
std::string true_cxx =
#ifdef __clang__
"clang++";
#elif defined(__GNU__)
"g++";
#elif defined(__MINGW32__)
"MinGW";
#elif defined(_MSC_VER)
"Visual Studio";
#else
"Compiler not identified";
#endif
std::string true_cxx_ver =
#ifdef __clang__
ver_string(__clang_major__, __clang_minor__, __clang_patchlevel__);
#elif defined(__GNU__)
ver_string(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#elif defined(__MINGW32__)
ver_string(__MINGW32__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
#elif defined( _MSC_VER)
ver_string(_MSC_VER, _MSC_FULL_VER,_MSC_BUILD);
#else
"";
#endif
IniFileParser::IniFileParser(Configuration* config)
{
_config = config;
......@@ -97,6 +132,25 @@ bool IniFileParser::Parse(std::string iniFile)
Log->Write("ERROR:\t Wrong header version. Only version greater than %s is supported.", JPS_OLD_VERSION);
return false;
}
//logfile
if (xMainNode->FirstChild("logfile")) {
_config->SetErrorLogFile(
_config->GetProjectRootDir()+xMainNode->FirstChild("logfile")->FirstChild()->Value());
_config->SetLog(2);
Log->Write("INFO:\tlogfile <%s>", _config->GetErrorLogFile().c_str());
}
Log->Write("----\nJuPedSim - JPScore\n");
Log->Write("Current date : %s %s", __DATE__, __TIME__);
Log->Write("Version : %s", JPSCORE_VERSION);
Log->Write("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Log->Write("Commit hash : %s", GIT_COMMIT_HASH);
Log->Write("Commit date : %s", GIT_COMMIT_DATE);
Log->Write("Branch : %s\n----\n", GIT_BRANCH);
//seed
if (xMainNode->FirstChild("seed")) {
TiXmlNode* seedNode = xMainNode->FirstChild("seed")->FirstChild();
......@@ -149,13 +203,6 @@ bool IniFileParser::Parse(std::string iniFile)
_config->SetMaxOpenMPThreads(omp_get_max_threads());
Log->Write("INFO:\tUsing num_threads <%d> threads (%d available)", _config->GetMaxOpenMPThreads(), max_threads);
//logfile
if (xMainNode->FirstChild("logfile")) {
_config->SetErrorLogFile(
_config->GetProjectRootDir()+xMainNode->FirstChild("logfile")->FirstChild()->Value());
_config->SetLog(2);
Log->Write("INFO:\tlogfile <%s>", _config->GetErrorLogFile().c_str());
}
//display statistics
if (xMainNode->FirstChild("show_statistics")) {
std::string value = xMainNode->FirstChild("show_statistics")->FirstChild()->Value();
......
......@@ -95,7 +95,7 @@ bool Simulation::InitArgs()
}
case 2: {
char name[CLENGTH] = "";
sprintf(name, "%s.P0.dat", _config->GetErrorLogFile().c_str());
sprintf(name, "%s.txt", _config->GetErrorLogFile().c_str());
if (Log)
delete Log;
Log = new FileHandler(name);
......@@ -346,7 +346,7 @@ void Simulation::UpdateRoutesAndLocations()
//exit(EXIT_FAILURE);
#pragma omp critical(Simulation_Update_pedsToRemove)
{
pedsToRemove.push_back(ped);
pedsToRemove.insert(ped);
Log->incrementDeletedAgents();
}
}
......
......@@ -49,14 +49,15 @@
using namespace std;
void ArgumentParser::Usage(const std::string file)
{
fprintf(stderr, "\n\nYou are actually using JuPedsim version %s \n\n", JPS_VERSION);
fprintf(stderr, "Usages: \n");
fprintf(stderr, " %s <path to file> start the simulation with the specified file.\n", file.c_str());
fprintf(stderr, " %s search and use the file ini.xml in the current directory.\n",
file.c_str());
fprintf(stderr, " %s -v/--version display the current version.\n", file.c_str());
fprintf(stderr, " %s -h/--help display this text.\n", file.c_str());
#ifdef _JPS_AS_A_SERVICE
fprintf(stderr, " %s --as-a-service -p <port nr> runs jps as a service at port <port nr>.\n", file.c_str());
......@@ -77,6 +78,15 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
if (argc==1) {
Log->Write(
"INFO: \tTrying to load the default configuration from the file <ini.xml>");
// first logs will go to stdout
Log->Write("----\nJuPedSim - JPScore\n");
Log->Write("Current date : %s %s", __DATE__, __TIME__);
Log->Write("Version : %s", JPSCORE_VERSION);
// Log->Write("Compiler : %s (%s)", true_cxx.c_str(), true_cxx_ver.c_str());
Log->Write("Commit hash : %s", GIT_COMMIT_HASH);
Log->Write("Commit date : %s", GIT_COMMIT_DATE);
Log->Write("Branch : %s\n----\n", GIT_BRANCH);
IniFileParser* p = new IniFileParser(_config);
if (!p->Parse("ini.xml")) {
Usage(argv[0]);
......@@ -90,10 +100,6 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
Usage(argv[0]);
return false;
}
else if (argument=="-v" || argument=="--version") {
fprintf(stderr, "You are actually using JuPedsim/jpscore version %s \n\n", JPS_VERSION);
return false;
}
// other special case where a single configuration file is submitted
//check if inifile options are given
......@@ -161,4 +167,3 @@ bool ArgumentParser::ParseArgs(int argc, char** argv)
Usage(argv[0]);
return false;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment