From 647546c1b5b7092481e4c711d997a6073262d695 Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Fri, 8 Dec 2017 17:12:03 +0100 Subject: [PATCH] Add log levels for TLMErrorLog class. --- ADAMS/tlmforce.cc | 2 +- FMIWrapper/main.cpp | 147 +++++++++--------- Hopsan/TLMPluginLib/TLMPluginHandler.hpp | 13 +- .../TLMPluginInterfaceSignalOutput.hpp | 1 + Hopsan/TLMPluginLib/common.h | 12 +- Modelica/tlmforce.cc | 9 +- OMFMISimulatorWrapper/main.cpp | 4 +- OpenModelica/tlmforce.cc | 14 +- Simulink/tlmforce.cc | 38 ++--- Simulink/tlmsignal.cc | 28 ++-- Simulink/tlmsignaloutput.cc | 22 +-- common/Communication/ManagerCommHandler.cc | 79 +++++----- common/Communication/ManagerCommHandler.h | 4 +- common/Communication/TLMClientComm.cc | 38 +++-- common/Communication/TLMCommUtil.cc | 12 +- common/Communication/TLMManagerComm.cc | 4 +- common/CompositeModels/CompositeModel.cc | 34 ++-- .../CompositeModels/CompositeModelReader.cc | 36 ++--- common/Interfaces/TLMInterface.cc | 2 +- common/Interfaces/TLMInterface1D.cc | 35 +++-- common/Interfaces/TLMInterface3D.cc | 42 ++--- common/Interfaces/TLMInterfaceSignal.cc | 6 +- common/Interfaces/TLMInterfaceSignalOutput.cc | 12 +- common/Logging/TLMErrorLog.cc | 66 ++++---- common/Logging/TLMErrorLog.h | 28 ++-- common/ManagerMain.cc | 7 +- common/MonitorMain.cc | 27 ++-- common/Parameters/ComponentParameter.cc | 2 +- common/Plugin/MonitoringPluginImplementer.cc | 15 +- common/Plugin/PluginImplementer.cc | 62 ++++---- common/Plugin/PluginImplementer.h | 11 -- common/Plugin/TLMPlugin.h | 10 -- common/TLMTestApp.cc | 1 - 33 files changed, 413 insertions(+), 410 deletions(-) diff --git a/ADAMS/tlmforce.cc b/ADAMS/tlmforce.cc index 7dccb37..fc63292 100644 --- a/ADAMS/tlmforce.cc +++ b/ADAMS/tlmforce.cc @@ -128,7 +128,7 @@ TLM_force::~TLM_force() { } void TLM_force::SetDebugOut(){ - Plugin->SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } TLM_force* TLM_force::GetInstance(bool debugFlg) diff --git a/FMIWrapper/main.cpp b/FMIWrapper/main.cpp index ed7640a..d80bde2 100644 --- a/FMIWrapper/main.cpp +++ b/FMIWrapper/main.cpp @@ -156,7 +156,7 @@ void setParameters() double value_real = atof(value.c_str()); std::stringstream ss; ss << "Setting parameter: " << vr << " to " << value_real; - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); fmi2_import_set_real(fmu,&vr,1,&value_real); } } @@ -409,7 +409,7 @@ void fmiLogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, TLMErrorLog::Warning(ss.str()); break; default: - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); break; } } @@ -444,11 +444,11 @@ int simulate_fmi2_cs() TLMErrorLog::FatalError("Could not create the DLL loading mechanism(C-API). Error: "+string(fmi2_import_get_last_error(fmu))); } - TLMErrorLog::Log("Version returned from FMU: "+string(fmi2_import_get_version(fmu))); - TLMErrorLog::Log("Platform type returned: "+string(fmi2_import_get_types_platform(fmu))); + TLMErrorLog::Info("Version returned from FMU: "+string(fmi2_import_get_version(fmu))); + TLMErrorLog::Info("Platform type returned: "+string(fmi2_import_get_types_platform(fmu))); fmuGUID = fmi2_import_get_GUID(fmu); - TLMErrorLog::Log("GUID: "+string(fmuGUID)); + TLMErrorLog::Info("GUID: "+string(fmuGUID)); jmstatus = fmi2_import_instantiate(fmu, instanceName, fmi2_cosimulation, fmuLocation, visible); @@ -533,7 +533,7 @@ int simulate_fmi2_cs() } //Take one sub step - TLMErrorLog::Log("Taking step!"); + TLMErrorLog::Info("Taking step!"); fmistatus = fmi2_import_do_step(fmu,tcur,hsub,fmi2_true); //Increment time @@ -584,7 +584,7 @@ int simulate_fmi2_cs() } } - TLMErrorLog::Log("Simulation finished."); + TLMErrorLog::Info("Simulation finished."); fmistatus = fmi2_import_terminate(fmu); @@ -648,19 +648,19 @@ void motionFromFmuToTlm(double tcur) // Simulate function for model exchange int simulate_fmi2_me() { - TLMErrorLog::Log("Starting simulation using FMI for Model Exchange."); + TLMErrorLog::Info("Starting simulation using FMI for Model Exchange."); switch (simConfig.solver) { case CVODE: - TLMErrorLog::Log("Using CVODE solver."); + TLMErrorLog::Info("Using CVODE solver."); break; case IDA: - TLMErrorLog::Log("Using IDA solver."); + TLMErrorLog::Info("Using IDA solver."); break; case ExplicitEuler: - TLMErrorLog::Log("Using explicit Euler solver."); + TLMErrorLog::Info("Using explicit Euler solver."); break; case RungeKutta: - TLMErrorLog::Log("Using 4th order explicit Runge-Kutta solver."); + TLMErrorLog::Info("Using 4th order explicit Runge-Kutta solver."); } jm_status_enu_t jmstatus; @@ -695,11 +695,11 @@ int simulate_fmi2_me() TLMErrorLog::FatalError("Could not create the DLL loading mechanism(C-API). Error: "+string(fmi2_import_get_last_error(fmu))); } - TLMErrorLog::Log("Version returned from FMU: "+string(fmi2_import_get_version(fmu))); - TLMErrorLog::Log("Platform type returned: "+string(fmi2_import_get_types_platform(fmu))); + TLMErrorLog::Info("Version returned from FMU: "+string(fmi2_import_get_version(fmu))); + TLMErrorLog::Info("Platform type returned: "+string(fmi2_import_get_types_platform(fmu))); fmuGUID = fmi2_import_get_GUID(fmu); - TLMErrorLog::Log("GUID: "+string(fmuGUID)); + TLMErrorLog::Info("GUID: "+string(fmuGUID)); n_states = fmi2_import_get_number_of_continuous_states(fmu); n_event_indicators = fmi2_import_get_number_of_event_indicators(fmu); @@ -720,7 +720,7 @@ int simulate_fmi2_me() setParameters(); fmi2_import_set_debug_logging(fmu, fmi2_false, 0, 0); - TLMErrorLog::Log("fmi2_import_set_debug_logging: " + string(fmi2_status_to_string(fmistatus))); + TLMErrorLog::Info("fmi2_import_set_debug_logging: " + string(fmi2_status_to_string(fmistatus))); fmi2_import_set_debug_logging(fmu, fmi2_true, 0, 0); relativeTolerance = fmi2_import_get_default_experiment_tolerance(fmu); @@ -791,14 +791,14 @@ int simulate_fmi2_me() } /* Set the vector absolute tolerance */ - TLMErrorLog::Log("n_states = "+TLMErrorLog::ToStdStr(int(n_states))); + TLMErrorLog::Info("n_states = "+TLMErrorLog::ToStdStr(int(n_states))); for(size_t i=0; i i+1) { @@ -1364,15 +1359,15 @@ int main(int argc, char* argv[]) cout << "Starting FMIWrapper. Debug output will be written to \"TLMlogfile.log\"." << endl; // for(int i=0; iRegisteTLMInterface(fmiConfig.interfaceNames[i], fmiConfig.dimensions[i], fmiConfig.causalities[i], @@ -1486,7 +1481,7 @@ int main(int argc, char* argv[]) int parId = plugin->RegisterComponentParameter(name,value); plugin->GetParameterValue(parId, name, value); - TLMErrorLog::Log("Received value: "+value+" for parameter "+name); + TLMErrorLog::Info("Received value: "+value+" for parameter "+name); fmi2_value_reference_t vr = fmi2_import_get_variable_vr(var); parameterMap.insert(std::pair(vr,value)); } @@ -1497,15 +1492,15 @@ int main(int argc, char* argv[]) // Start simulation switch(kind) { case fmi2_fmu_kind_cs: - TLMErrorLog::Log("FMU kind is co-simulation."); + TLMErrorLog::Info("FMU kind is co-simulation."); simulate_fmi2_cs(); break; case fmi2_fmu_kind_me: - TLMErrorLog::Log("FMU kind is model exchange."); + TLMErrorLog::Info("FMU kind is model exchange."); simulate_fmi2_me(); break; case fmi2_fmu_kind_me_and_cs: //Not sure how to handle FMUs that can be both kinds, guess ME better than CS - TLMErrorLog::Log("FMU kind is either co-simulation or model exchange."); + TLMErrorLog::Info("FMU kind is either co-simulation or model exchange."); simulate_fmi2_me(); break; case fmi2_fmu_kind_unknown: @@ -1520,7 +1515,7 @@ int main(int argc, char* argv[]) plugin->AwaitClosePermission(); - TLMErrorLog::Log("FMIWrapper completed successfully!"); + TLMErrorLog::Info("FMIWrapper completed successfully!"); return 0; } diff --git a/Hopsan/TLMPluginLib/TLMPluginHandler.hpp b/Hopsan/TLMPluginLib/TLMPluginHandler.hpp index 31bdf8a..d7e795a 100644 --- a/Hopsan/TLMPluginLib/TLMPluginHandler.hpp +++ b/Hopsan/TLMPluginLib/TLMPluginHandler.hpp @@ -84,7 +84,10 @@ namespace hopsan { TLMErrorLog::SetOutStream(mDebugOutFile); } - TLMErrorLog::SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); + } + else { + TLMErrorLog::SetLogLevel(TLMLogLevel::Warning); } //Register parameters @@ -95,11 +98,11 @@ namespace hopsan { { HString parValue; mpSystemParent->getParameterValue(parNames[i],parValue); - TLMErrorLog::Log("Registers parameter: "+h2s(parNames[i])); + TLMErrorLog::Info("Registers parameter: "+h2s(parNames[i])); mParIds.push_back(mpPlugin->RegisterComponentParameter(h2s(parNames[i]),h2s(parValue))); std::stringstream ss; ss << "Hopsan got parameter ID: " << mParIds[mParIds.size()-1]; - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); } //Receive parameter values @@ -108,11 +111,11 @@ namespace hopsan { std::string name, value; std::stringstream ss; ss << "Requesting value for parameter " << mParIds[i]; - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); mpPlugin->GetParameterValue(mParIds[i], name, value); std::stringstream ss2; ss2 << "Got name \"" << name << "\" and value \"" << value << "\""; - TLMErrorLog::Log(ss2.str()); + TLMErrorLog::Info(ss2.str()); mpSystemParent->setParameterValue(HString(name.c_str()),HString(value.c_str())); } diff --git a/Hopsan/TLMPluginLib/TLMPluginInterfaceSignalOutput.hpp b/Hopsan/TLMPluginLib/TLMPluginInterfaceSignalOutput.hpp index 3a51593..9fb658b 100644 --- a/Hopsan/TLMPluginLib/TLMPluginInterfaceSignalOutput.hpp +++ b/Hopsan/TLMPluginLib/TLMPluginInterfaceSignalOutput.hpp @@ -55,6 +55,7 @@ namespace hopsan { void initialize() { bool foundHandler = false; + for(size_t i=0; igetSubComponents().size(); ++i) { if(mpSystemParent->getSubComponents()[i]->getTypeName() == "TLMPluginHandler") diff --git a/Hopsan/TLMPluginLib/common.h b/Hopsan/TLMPluginLib/common.h index 1443150..9bf08b0 100644 --- a/Hopsan/TLMPluginLib/common.h +++ b/Hopsan/TLMPluginLib/common.h @@ -33,18 +33,18 @@ inline tlmConfig_t readTlmConfigFile(std::string path) } //Print results to log file - TLMErrorLog::Log("---"+std::string(TLM_CONFIG_FILE_NAME)+"---"); - TLMErrorLog::Log("model: "+tlmConfig.model); - TLMErrorLog::Log("server: "+tlmConfig.server); + TLMErrorLog::Info("---"+std::string(TLM_CONFIG_FILE_NAME)+"---"); + TLMErrorLog::Info("model: "+tlmConfig.model); + TLMErrorLog::Info("server: "+tlmConfig.server); std::stringstream ss1; ss1 << "tstart: " << tlmConfig.tstart; - TLMErrorLog::Log(ss1.str()); + TLMErrorLog::Info(ss1.str()); std::stringstream ss2; ss2 << "tend: " << tlmConfig.tend; - TLMErrorLog::Log(ss2.str()); + TLMErrorLog::Info(ss2.str()); std::stringstream ss3; ss3 << "hmax: " << tlmConfig.hmax; - TLMErrorLog::Log(ss3.str()); + TLMErrorLog::Info(ss3.str()); return tlmConfig; } diff --git a/Modelica/tlmforce.cc b/Modelica/tlmforce.cc index d238b92..075f80a 100644 --- a/Modelica/tlmforce.cc +++ b/Modelica/tlmforce.cc @@ -73,7 +73,7 @@ void initialize_TLM() TLMErrorLog::SetOutStream(debugOutFile); } - TLMErrorLog::SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } if(!tlmConfigFile.good()) { @@ -127,7 +127,12 @@ void set_debug_mode(int debugFlgIn) cerr << "Debug off" << endl; } - TLMErrorLog::SetDebugOut(debugFlg); + if(debugFlg) { + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); + } + else { + TLMErrorLog::SetLogLevel(TLMLogLevel::Warning); + } } double get_tlm_delay() diff --git a/OMFMISimulatorWrapper/main.cpp b/OMFMISimulatorWrapper/main.cpp index 8804cdf..62fe041 100644 --- a/OMFMISimulatorWrapper/main.cpp +++ b/OMFMISimulatorWrapper/main.cpp @@ -149,9 +149,7 @@ int main(int argc, char *argv[]) TLMErrorLog::SetOutStream(DebugOutFile); } - TLMErrorLog::SetDebugOut(true); - TLMErrorLog::SetNormalErrorLogOn(true); - TLMErrorLog::SetWarningOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } for(size_t i=0; ireferenceCount == TLMPluginStructObj->registerCount); @@ -459,7 +461,7 @@ void set_tlm_output_value(void* in_TLMPluginStructObj, double simTime, // Current simulation time double value) // Output force { - TLMErrorLog::Log("CALLING: set_tlm_output_value(time = "+TLMErrorLog::ToStdStr(simTime)+")"); + TLMErrorLog::Info("CALLING: set_tlm_output_value(time = "+TLMErrorLog::ToStdStr(simTime)+")"); TLMPluginStruct* TLMPluginStructObj = (TLMPluginStruct*)in_TLMPluginStructObj; // Check if interface is registered. If it's not, register it diff --git a/Simulink/tlmforce.cc b/Simulink/tlmforce.cc index e915c90..36b2173 100644 --- a/Simulink/tlmforce.cc +++ b/Simulink/tlmforce.cc @@ -81,7 +81,7 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): maxStep = 1.0e-10; } - TLMErrorLog::Log( "Try to initialize Simulink plugin." ); + TLMErrorLog::Info( "Try to initialize Simulink plugin." ); if(! Plugin->Init( model, timeStart, @@ -92,14 +92,14 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): exit(1); } - TLMErrorLog::Log( "TLM Simulink plugin was initialized" ); + TLMErrorLog::Info( "TLM Simulink plugin was initialized" ); } TLM_InterfaceReg::~TLM_InterfaceReg() { } void TLM_InterfaceReg::SetDebugOut(){ - Plugin->SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) @@ -113,7 +113,7 @@ TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) void TLM_InterfaceReg::RegisterInterface(std::string ifID, int dimensions, std::string causality, std::string domain) { // No way to get the real marker name from the solver - using "M" - TLMErrorLog::Log( "Trying to register interface " + ifID ); + TLMErrorLog::Info( "Trying to register interface " + ifID ); if( InterfaceIDmap.count(ifID) > 0 ){ TLMErrorLog::FatalError( "Try to register same interface twice " + ifID ); @@ -268,7 +268,7 @@ static void mdlInitializeSampleTimes(SimStruct *S) TLM_InterfaceReg::GetInstance(false)->GetSimParameters(sTime, eTime, timeStep); // true or false in GetInstance(...) enables/disables debug output - TLMErrorLog::Log("Set sample time to " + ToStr(timeStep)); + TLMErrorLog::Info("Set sample time to " + ToStr(timeStep)); /* Set TLM delay here! */ ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); @@ -361,10 +361,10 @@ static void mdlOutputs(SimStruct *S, int_T tid) force); - TLMErrorLog::Log("Got force for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("F: " + ToStr(force[0]) + " " + ToStr(force[1]) + " " + ToStr(force[2]) ); - TLMErrorLog::Log("M: " + ToStr(force[3]) + " " + ToStr(force[4]) + " " + ToStr(force[5]) ); + TLMErrorLog::Info("Got force for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("F: " + ToStr(force[0]) + " " + ToStr(force[1]) + " " + ToStr(force[2]) ); + TLMErrorLog::Info("M: " + ToStr(force[3]) + " " + ToStr(force[4]) + " " + ToStr(force[5]) ); #ifdef DEBUGFLG if( isnan(force[0]) || isnan(force[1]) || isnan(force[2]) ){ @@ -376,8 +376,8 @@ static void mdlOutputs(SimStruct *S, int_T tid) /* Get Position and Orientation */ TLM_InterfaceReg::GetInstance()->GetPlugin()->GetTimeData3D(ifID, time, CurTimeData); - TLMErrorLog::Log("Got position for: " + std::string(name) ); - TLMErrorLog::Log("R: " + ToStr(CurTimeData.Position[0]) + " " + ToStr(CurTimeData.Position[1]) + " " + ToStr(CurTimeData.Position[2]) ); + TLMErrorLog::Info("Got position for: " + std::string(name) ); + TLMErrorLog::Info("R: " + ToStr(CurTimeData.Position[0]) + " " + ToStr(CurTimeData.Position[1]) + " " + ToStr(CurTimeData.Position[2]) ); } else { @@ -446,14 +446,14 @@ static void mdlOutputs(SimStruct *S, int_T tid) int ifID = TLM_InterfaceReg::GetInstance()->GetInterfaceID(name); if( ifID >= 0 ){ - TLMErrorLog::Log("Call SetMotion for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("R: " + ToStr(R[0]) + " " + ToStr(R[1]) + " " + ToStr(R[2]) ); - //TLMErrorLog::Log("A0: " + ToStr(A[0]) + " " + ToStr(A[1]) + " " + ToStr(A[2]) ); - //TLMErrorLog::Log("A1: " + ToStr(A[3]) + " " + ToStr(A[4]) + " " + ToStr(A[5]) ); - //TLMErrorLog::Log("A2: " + ToStr(A[6]) + " " + ToStr(A[7]) + " " + ToStr(A[8]) ); - TLMErrorLog::Log("vR: " + ToStr(vR[0]) + " " + ToStr(vR[1]) + " " + ToStr(vR[2]) ); - //TLMErrorLog::Log("Omega: " + ToStr(Omega[0]) + " " + ToStr(Omega[1]) + " " + ToStr(Omega[2]) ); + TLMErrorLog::Info("Call SetMotion for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("R: " + ToStr(R[0]) + " " + ToStr(R[1]) + " " + ToStr(R[2]) ); + //TLMErrorLog::Info("A0: " + ToStr(A[0]) + " " + ToStr(A[1]) + " " + ToStr(A[2]) ); + //TLMErrorLog::Info("A1: " + ToStr(A[3]) + " " + ToStr(A[4]) + " " + ToStr(A[5]) ); + //TLMErrorLog::Info("A2: " + ToStr(A[6]) + " " + ToStr(A[7]) + " " + ToStr(A[8]) ); + TLMErrorLog::Info("vR: " + ToStr(vR[0]) + " " + ToStr(vR[1]) + " " + ToStr(vR[2]) ); + //TLMErrorLog::Info("Omega: " + ToStr(Omega[0]) + " " + ToStr(Omega[1]) + " " + ToStr(Omega[2]) ); TLM_InterfaceReg::GetInstance()->GetPlugin()->SetMotion3D(ifID, // Send data to the Plugin time, diff --git a/Simulink/tlmsignal.cc b/Simulink/tlmsignal.cc index 77af7ba..c9f5ebc 100644 --- a/Simulink/tlmsignal.cc +++ b/Simulink/tlmsignal.cc @@ -83,7 +83,7 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): maxStep = 1.0e-10; } - TLMErrorLog::Log( "Try to initialize Simulink plugin." ); + TLMErrorLog::Info( "Try to initialize Simulink plugin." ); if(! Plugin->Init( model, timeStart, @@ -94,14 +94,14 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): exit(1); } - TLMErrorLog::Log( "TLM Simulink plugin was initialized" ); + TLMErrorLog::Info( "TLM Simulink plugin was initialized" ); } TLM_InterfaceReg::~TLM_InterfaceReg() { } void TLM_InterfaceReg::SetDebugOut(){ - Plugin->SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) @@ -115,7 +115,7 @@ TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) void TLM_InterfaceReg::RegisterInterface(std::string ifID, int dimensions, std::string causality, std::string domain) { // No way to get the real marker name from the solver - using "M" - TLMErrorLog::Log( "Trying to register interface " + ifID ); + TLMErrorLog::Info( "Trying to register interface " + ifID ); if( InterfaceIDmap.count(ifID) > 0 ){ TLMErrorLog::FatalError( "Try to register same interface twice " + ifID ); @@ -265,7 +265,7 @@ static void mdlInitializeSampleTimes(SimStruct *S) TLM_InterfaceReg::GetInstance(true)->GetSimParameters(sTime, eTime, timeStep); // true or false in GetInstance(...) enables/disables debug output - TLMErrorLog::Log("Set sample time to " + ToStr(timeStep)); + TLMErrorLog::Info("Set sample time to " + ToStr(timeStep)); /* Set TLM delay here! */ ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); @@ -360,9 +360,9 @@ static void mdlOutputs(SimStruct *S, int_T tid) time, value); - TLMErrorLog::Log("Got value for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("y: " + ToStr(*value)); + TLMErrorLog::Info("Got value for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("y: " + ToStr(*value)); #ifdef DEBUGFLG @@ -402,9 +402,9 @@ static void mdlOutputs(SimStruct *S, int_T tid) // int ifID = TLM_InterfaceReg::GetInstance()->GetInterfaceID(name); // if( ifID >= 0 ){ -// TLMErrorLog::Log("Call SetValueSignal for: " + std::string(name) ); -// TLMErrorLog::Log("time: " + ToStr(time) ); -// TLMErrorLog::Log("u: " + ToStr(*u) ); +// TLMErrorLog::Info("Call SetValueSignal for: " + std::string(name) ); +// TLMErrorLog::Info("time: " + ToStr(time) ); +// TLMErrorLog::Info("u: " + ToStr(*u) ); // TLM_InterfaceReg::GetInstance()->GetPlugin()->SetValueSignal(ifID, // Send data to the Plugin // time, @@ -443,9 +443,9 @@ static void mdlUpdate(SimStruct *S, int_T tid) int ifID = TLM_InterfaceReg::GetInstance()->GetInterfaceID(name); if( ifID >= 0 ){ - TLMErrorLog::Log("Call SetValueSignal for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("u: " + ToStr(*u) ); + TLMErrorLog::Info("Call SetValueSignal for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("u: " + ToStr(*u) ); TLM_InterfaceReg::GetInstance()->GetPlugin()->SetValueSignal(ifID, // Send data to the Plugin time, diff --git a/Simulink/tlmsignaloutput.cc b/Simulink/tlmsignaloutput.cc index 60c3d1d..fbc195e 100644 --- a/Simulink/tlmsignaloutput.cc +++ b/Simulink/tlmsignaloutput.cc @@ -83,7 +83,7 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): maxStep = 1.0e-10; } - TLMErrorLog::Log( "Try to initialize Simulink plugin." ); + TLMErrorLog::Info( "Try to initialize Simulink plugin." ); if(! Plugin->Init( model, timeStart, @@ -94,14 +94,14 @@ TLM_InterfaceReg::TLM_InterfaceReg(bool debugFlg): exit(1); } - TLMErrorLog::Log( "TLM Simulink plugin was initialized" ); + TLMErrorLog::Info( "TLM Simulink plugin was initialized" ); } TLM_InterfaceReg::~TLM_InterfaceReg() { } void TLM_InterfaceReg::SetDebugOut(){ - Plugin->SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) @@ -115,7 +115,7 @@ TLM_InterfaceReg* TLM_InterfaceReg::GetInstance(bool debugFlg) void TLM_InterfaceReg::RegisterInterface(std::string ifID, std::string type) { // No way to get the real marker name from the solver - using "M" - TLMErrorLog::Log( "Trying to register interface " + ifID ); + TLMErrorLog::Info( "Trying to register interface " + ifID ); if( InterfaceIDmap.count(ifID) > 0 ){ TLMErrorLog::FatalError( "Try to register same interface twice " + ifID ); @@ -256,7 +256,7 @@ static void mdlInitializeSampleTimes(SimStruct *S) TLM_InterfaceReg::GetInstance(true)->GetSimParameters(sTime, eTime, timeStep); // true or false in GetInstance(...) enables/disables debug output - TLMErrorLog::Log("Set sample time to " + ToStr(timeStep)); + TLMErrorLog::Info("Set sample time to " + ToStr(timeStep)); /* Set TLM delay here! */ ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME); @@ -330,9 +330,9 @@ static void mdlOutputs(SimStruct *S, int_T tid) time, *u); - TLMErrorLog::Log("Set value for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("u: " + ToStr(*u)); + TLMErrorLog::Info("Set value for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("u: " + ToStr(*u)); #ifdef DEBUGFLG @@ -373,9 +373,9 @@ static void mdlOutputs(SimStruct *S, int_T tid) int ifID = TLM_InterfaceReg::GetInstance()->GetInterfaceID(name); if( ifID >= 0 ){ - TLMErrorLog::Log("Call SetValueSignal for: " + std::string(name) ); - TLMErrorLog::Log("time: " + ToStr(time) ); - TLMErrorLog::Log("u: " + ToStr(*u) ); + TLMErrorLog::Info("Call SetValueSignal for: " + std::string(name) ); + TLMErrorLog::Info("time: " + ToStr(time) ); + TLMErrorLog::Info("u: " + ToStr(*u) ); TLM_InterfaceReg::GetInstance()->GetPlugin()->SetValueSignal(ifID, // Send data to the Plugin time, diff --git a/common/Communication/ManagerCommHandler.cc b/common/Communication/ManagerCommHandler.cc index 6c41367..8fc1ef6 100644 --- a/common/Communication/ManagerCommHandler.cc +++ b/common/Communication/ManagerCommHandler.cc @@ -95,7 +95,7 @@ void ManagerCommHandler::RunStartupProtocol() { // Start the external components forming "coupled simulation" TheModel.StartComponents(); - TLMErrorLog::Log("----- Waiting for registration requests ----- "); + TLMErrorLog::Info("----- Waiting for registration requests ----- "); Comm.AddActiveSocket(acceptSocket); // Setup timer @@ -119,7 +119,7 @@ void ManagerCommHandler::RunStartupProtocol() { // Restart is needed for correct time accumulation. TM_Start(&tInfo); - TLMErrorLog::Log("Communicating with clients..."); + TLMErrorLog::Info("Communicating with clients..."); Comm.ClearActiveSockets(); // Check all the components for interface registration messages @@ -143,20 +143,20 @@ void ManagerCommHandler::RunStartupProtocol() { if(message->Header.MessageType == TLMMessageTypeConst::TLM_CHECK_MODEL) { // This component is done with registration. It's will wait for others - TLMErrorLog::Log(string("Component ") + comp.GetName() + " is ready to simulation");; + TLMErrorLog::Info(string("Component ") + comp.GetName() + " is ready to simulation");; comp.SetReadyToSim(); numCheckModel++; } else if(message->Header.MessageType == TLMMessageTypeConst::TLM_REG_PARAMETER) { - TLMErrorLog::Log(string("Component ") + comp.GetName() + " registers parameter"); + TLMErrorLog::Info(string("Component ") + comp.GetName() + " registers parameter"); Comm.AddActiveSocket(hdl); ProcessRegParameterMessage(iSock, *message); MessageQueue.PutWriteSlot(message); } else { - TLMErrorLog::Log(string("Component ") + comp.GetName() + " registers interface");; + TLMErrorLog::Info(string("Component ") + comp.GetName() + " registers interface");; Comm.AddActiveSocket(hdl); // expect more messages ProcessRegInterfaceMessage(iSock, *message); @@ -186,7 +186,7 @@ void ManagerCommHandler::RunStartupProtocol() { MessageQueue.PutWriteSlot(message); numToRegister --; if(numToRegister == 0) - TLMErrorLog::Log("All expected components are registered"); + TLMErrorLog::Info("All expected components are registered"); Comm.AddActiveSocket(hdl); } @@ -224,7 +224,7 @@ void ManagerCommHandler::ProcessRegComponentMessage(TLMMessage& mess) { mess.Header.TLMInterfaceID = CompID; - TLMErrorLog::Log(string("Component ") + aName + " is connected"); + TLMErrorLog::Info(string("Component ") + aName + " is connected"); } @@ -243,7 +243,7 @@ void ManagerCommHandler::ProcessRegInterfaceMessage(int compID, TLMMessage& mess // First, find the interface in the meta model string aSpecification ((const char*)(& mess.Data[0]), mess.Header.DataSize); - TLMErrorLog::Log("Manager received nameAndType: "+aSpecification); + TLMErrorLog::Info("Manager received nameAndType: "+aSpecification); string aName, dimStr, causality, domain; if(aSpecification.find(':') == std::string::npos) { //This is for backwards compatibility with BEAST. @@ -324,12 +324,12 @@ void ManagerCommHandler::ProcessRegInterfaceMessage(int compID, TLMMessage& mess } else if(CommMode == InterfaceRequestMode) { - TLMErrorLog::Log(string("Register TLM interface ") + + TLMErrorLog::Info(string("Register TLM interface ") + TheModel.GetTLMComponentProxy(compID).GetName() + '.' + aName); std::stringstream ss; ss << "Assigning interface ID = " << IfcID; - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); mess.Header.TLMInterfaceID = IfcID; TLMInterfaceProxy& ifc = TheModel.GetTLMInterfaceProxy(IfcID); @@ -353,7 +353,7 @@ void ManagerCommHandler::ProcessRegParameterMessage(int compID, TLMMessage &mess // First, find the interface in the meta model string aNameAndValue((const char*)(& mess.Data[0]), mess.Header.DataSize); - TLMErrorLog::Log("Manager received nameAndValue: "+aNameAndValue); + TLMErrorLog::Info("Manager received nameAndValue: "+aNameAndValue); string aName, aValue; bool readingName=true; @@ -391,7 +391,7 @@ void ManagerCommHandler::ProcessRegParameterMessage(int compID, TLMMessage &mess std::stringstream ss; ss << "Assigning parameter ID = " << ParID; - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); mess.Header.ComponentParameterID = ParID; @@ -416,7 +416,7 @@ void ManagerCommHandler::SetupInterfaceConnectionMessage(int IfcID, std::string& return; } - TLMErrorLog::Log(string("Interface ") + aName + " is connected"); + TLMErrorLog::Info(string("Interface ") + aName + " is connected"); // Put connection parameters in the reply TLMConnection& conn = TheModel.GetTLMConnection(connID); @@ -494,7 +494,7 @@ void ManagerCommHandler::ReaderThreadRun() { return; } - TLMErrorLog::Log("------------------ Starting time data exchange ------------------"); + TLMErrorLog::Info("------------------ Starting time data exchange ------------------"); Comm.SwitchToRunningMode(); runningMode = RunMode; @@ -515,7 +515,7 @@ void ManagerCommHandler::ReaderThreadRun() { message->SocketHandle = hdl; if(TLMCommUtil::ReceiveMessage(*message)) { if(message->Header.MessageType == TLMMessageTypeConst::TLM_CLOSE_REQUEST) { - TLMErrorLog::Log("Received close permission request from "+comp.GetName()); + TLMErrorLog::Info("Received close permission request from "+comp.GetName()); closedSockets.push_back(iSock); nClosedSock++; } @@ -536,12 +536,13 @@ void ManagerCommHandler::ReaderThreadRun() { else { //Socket was closed without permission nClosedSock++; + TLMErrorLog::Info("nCLosedSock = " +std::to_string(nClosedSock)); } } } } - TLMErrorLog::Log("Simulation complete."); + TLMErrorLog::Info("Simulation complete."); for(int i=0; i= TLMLogLevel::Info) { + TLMErrorLog::Info(string("Forwarding from " + TheModel.GetTLMComponentProxy(src.GetComponentID()).GetName() + '.'+ src.GetName() + " to " + destComp.GetName() + '.' + dest.GetName())); @@ -622,7 +623,7 @@ void ManagerCommHandler::UnpackAndStoreTimeData(TLMMessage& message) { if(message.Header.MessageType != TLMMessageTypeConst::TLM_TIME_DATA) { std::stringstream ss; ss << "Message type = " << int(message.Header.MessageType); - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); TLMErrorLog::FatalError("Unexpected message received in ManagerCommHandler::UnpackAndStoreTimeData(...)"); } @@ -642,7 +643,7 @@ void ManagerCommHandler::UnpackAndStoreTimeData(TLMMessage& message) { // forward the time data TLMTimeData3D& data = ip.getTime0Data3D(); - TLMErrorLog::Log("Unpack and store 3D time data for " + ip.GetName()); + TLMErrorLog::Info("Unpack and store 3D time data for " + ip.GetName()); data = *Next; } else if(ip.GetDimensions() == 1 && ip.GetCausality() == "Bidirectional") { @@ -659,7 +660,7 @@ void ManagerCommHandler::UnpackAndStoreTimeData(TLMMessage& message) { // forward the time data TLMTimeData3D& data = ip.getTime0Data3D(); - TLMErrorLog::Log("Unpack and store 1D time data for " + ip.GetName()); + TLMErrorLog::Info("Unpack and store 1D time data for " + ip.GetName()); data.Position[0] = Next->Position; data.Position[1] = 0; data.Position[2] = 0; @@ -684,7 +685,7 @@ void ManagerCommHandler::UnpackAndStoreTimeData(TLMMessage& message) { // forward the time data TLMTimeData3D& data = ip.getTime0Data3D(); - TLMErrorLog::Log("Unpack and store signal time data for " + ip.GetName()); + TLMErrorLog::Info("Unpack and store signal time data for " + ip.GetName()); data.Position[0] = 1; data.Position[1] = 0; data.Position[2] = 0; @@ -719,7 +720,7 @@ int ManagerCommHandler::ProcessInterfaceMonitoringMessage(TLMMessage& message) { } } - TLMErrorLog::Log("Request for monitoring " + aName); + TLMErrorLog::Info("Request for monitoring " + aName); // Here the full name, i.e., component.interface, is requered int IfcID = TheModel.GetTLMInterfaceID(aName); @@ -772,8 +773,8 @@ void ManagerCommHandler::ForwardToMonitor(TLMMessage& message) { pos != monitorInterfaceMap.upper_bound(TLMInterfaceID); pos++) { - if(TLMErrorLog::IsNormalErrorLogOn()) { - TLMErrorLog::Log("Forwarding to monitor, interface " + TLMErrorLog::ToStdStr(TLMInterfaceID) + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info("Forwarding to monitor, interface " + TLMErrorLog::ToStdStr(TLMInterfaceID) + " on socket " + TLMErrorLog::ToStdStr(pos->second)); } @@ -794,8 +795,8 @@ void ManagerCommHandler::ForwardToMonitor(TLMMessage& message) { } } else { - if(TLMErrorLog::IsNormalErrorLogOn()) { - TLMErrorLog::Log("Nothing to forward for monitor interface " + TLMErrorLog::ToStdStr(TLMInterfaceID)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info("Nothing to forward for monitor interface " + TLMErrorLog::ToStdStr(TLMInterfaceID)); } } monitorMapLock.unlock(); @@ -803,14 +804,14 @@ void ManagerCommHandler::ForwardToMonitor(TLMMessage& message) { void ManagerCommHandler::MonitorThreadRun() { - TLMErrorLog::Log("In monitoring"); + TLMErrorLog::Info("In monitoring"); if(TheModel.GetSimParams().GetMonitorPort() <= 0) { - TLMErrorLog::Log("Monitoring disabled!"); + TLMErrorLog::Info("Monitoring disabled!"); return; } - TLMErrorLog::Log("Initialize monitoring port"); + TLMErrorLog::Info("Initialize monitoring port"); // Create a connection for max. 10 clients. TLMManagerComm monComm(10, TheModel.GetSimParams().GetMonitorPort()); @@ -833,7 +834,7 @@ void ManagerCommHandler::MonitorThreadRun() { // Never switch to running mode but use active sockets instead. monComm.AddActiveSocket(acceptSocket); - TLMErrorLog::Log("Wait for monitoring connections..."); + TLMErrorLog::Info("Wait for monitoring connections..."); std::vector socks; @@ -849,7 +850,7 @@ void ManagerCommHandler::MonitorThreadRun() { if(runningMode == ShutdownMode) break; if(monComm.HasData(acceptSocket)) { - TLMErrorLog::Log("Got new monitoring connection"); + TLMErrorLog::Info("Got new monitoring connection"); hdl = monComm.AcceptComponentConnections(); if(hdl < 0) { TLMErrorLog::FatalError("Failed to accept socket."); @@ -862,7 +863,7 @@ void ManagerCommHandler::MonitorThreadRun() { else { for(std::vector::iterator it=socks.begin(); it != socks.end(); it++) { if(monComm.HasData(*it)) { - TLMErrorLog::Log("Accepted data on monitoring connection"); + TLMErrorLog::Info("Accepted data on monitoring connection"); hdl = *it; break; @@ -898,7 +899,7 @@ void ManagerCommHandler::MonitorThreadRun() { if(IfcID >= 0) { - TLMErrorLog::Log("Register monitor handle for interface " + ToStr(IfcID)); + TLMErrorLog::Info("Register monitor handle for interface " + ToStr(IfcID)); #if 0 //std::cout << "hdl=" << hdl << ", ifID=" << IfcID << std::endl; localIntMap.insert(std::make_pair(hdl, IfcID)); diff --git a/common/Communication/ManagerCommHandler.h b/common/Communication/ManagerCommHandler.h index 61dfe51..b0cb14e 100644 --- a/common/Communication/ManagerCommHandler.h +++ b/common/Communication/ManagerCommHandler.h @@ -99,7 +99,7 @@ class ManagerCommHandler { #else Sleep(10); // milli seconds #endif - TLMErrorLog::Log("Waiting for monitor to connect"); + TLMErrorLog::Info("Waiting for monitor to connect"); } } @@ -150,7 +150,7 @@ class ManagerCommHandler { #else Sleep(10); // milli seconds #endif - TLMErrorLog::Log("Waiting for monitor to connect"); + TLMErrorLog::Info("Waiting for monitor to connect"); } } diff --git a/common/Communication/TLMClientComm.cc b/common/Communication/TLMClientComm.cc index 930e2b9..6f24908 100644 --- a/common/Communication/TLMClientComm.cc +++ b/common/Communication/TLMClientComm.cc @@ -110,8 +110,8 @@ void TLMClientComm::UnpackTimeDataMessageSignal(TLMMessage &mess, std::dequeh_addr, hp->h_length); @@ -214,14 +218,14 @@ int TLMClientComm::ConnectManager(string& callname, int portnr) { TLMErrorLog::FatalError("TLM: Can not contact TLM manager"); } else { - TLMErrorLog::Log("TLM manager host found, trying to connect..."); + TLMErrorLog::Info("TLM manager host found, trying to connect..."); } count = 0; while(connect(s, (struct sockaddr *) &sa, sizeof(sa)) < 0) { count++; - TLMErrorLog::Log(string("Connection attempt ") + TLMErrorLog::ToStdStr(count) + " failed"); + TLMErrorLog::Info(string("Connection attempt ") + TLMErrorLog::ToStdStr(count) + " failed"); if(count>=10) { #ifndef WIN32 close(s); @@ -232,13 +236,13 @@ int TLMClientComm::ConnectManager(string& callname, int portnr) { TLMErrorLog::FatalError("TLM: Can not connect to manager"); } - TLMErrorLog::Log("Pausing..."); + TLMErrorLog::Info("Pausing..."); #ifndef WIN32 usleep(count * count * 1000000); // micro seconds #else Sleep(count * count * 1000); // milli seconds #endif - TLMErrorLog::Log("Trying again..."); + TLMErrorLog::Info("Trying again..."); } @@ -261,10 +265,10 @@ void TLMClientComm::CreateInterfaceRegMessage(std::string& Name, int dimensions, std::stringstream ss; ss << Name << ":" << dimensions << ":" << causality << ":" << domain; std::string specification = ss.str(); - TLMErrorLog::Log("Client sends nameAndType: "+specification); + TLMErrorLog::Info("Client sends nameAndType: "+specification); #else std::string specification = Name; - TLMErrorLog::Log("Client sends name: "+specification); + TLMErrorLog::Info("Client sends name: "+specification); #endif mess.Header.DataSize = specification.length(); @@ -276,7 +280,7 @@ void TLMClientComm::CreateParameterRegMessage(std::string &Name, std::string &Va mess.Header.MessageType = TLMMessageTypeConst::TLM_REG_PARAMETER; std::string nameAndValue = Name+":"+Value; - TLMErrorLog::Log("Client sends nameAndValue: "+nameAndValue); + TLMErrorLog::Info("Client sends nameAndValue: "+nameAndValue); mess.Header.DataSize = nameAndValue.length(); mess.Data.resize(nameAndValue.length()); memcpy(&mess.Data[0], nameAndValue.c_str(), nameAndValue.length()); @@ -303,9 +307,9 @@ void TLMClientComm::UnpackRegInterfaceMessage(TLMMessage& mess, TLMConnectionPar } void TLMClientComm::UnpackRegParameterMessage(TLMMessage &mess, std::string &Value) { - TLMErrorLog::Log("Entering UnpackRegParameterMessage()"); + TLMErrorLog::Info("Entering UnpackRegParameterMessage()"); if(mess.Header.DataSize == 0) return; // non connected interface - TLMErrorLog::Log("DataSize is ok!"); + TLMErrorLog::Info("DataSize is ok!"); char ValueBuf[100]; if(mess.Header.DataSize != sizeof(ValueBuf)) { TLMErrorLog::FatalError("Wrong size of message in parameter registration : DataSize "+ @@ -325,5 +329,5 @@ void TLMClientComm::UnpackRegParameterMessage(TLMMessage &mess, std::string &Val memcpy(&ValueBuf, & mess.Data[0], mess.Header.DataSize); Value = std::string(ValueBuf); - TLMErrorLog::Log("Parameter received value: "+Value); + TLMErrorLog::Info("Parameter received value: "+Value); } diff --git a/common/Communication/TLMCommUtil.cc b/common/Communication/TLMCommUtil.cc index e112c99..f2cb14f 100644 --- a/common/Communication/TLMCommUtil.cc +++ b/common/Communication/TLMCommUtil.cc @@ -31,7 +31,7 @@ void TLMCommUtil::SendMessage(TLMMessage& mess) { int DataSize = mess.Header.DataSize; if(doDetailedLogging) { - TLMErrorLog::Log("SendMessage: wants to send "+ + TLMErrorLog::Info("SendMessage: wants to send "+ Int2Str(sizeof(TLMMessageHeader))+"+"+ Int2Str(DataSize)+ " bytes "); } @@ -61,7 +61,7 @@ void TLMCommUtil::SendMessage(TLMMessage& mess) { #endif if(doDetailedLogging) { - TLMErrorLog::Log("SendMessage:send() sent "+Int2Str(sendBytes)+ " bytes "); + TLMErrorLog::Info("SendMessage:send() sent "+Int2Str(sendBytes)+ " bytes "); } if(DataSize > 0) { @@ -78,7 +78,7 @@ void TLMCommUtil::SendMessage(TLMMessage& mess) { #endif if(doDetailedLogging) { - TLMErrorLog::Log("SendMessage:send()(part 2) sent "+Int2Str(sendBytes)+ " bytes "); + TLMErrorLog::Info("SendMessage:send()(part 2) sent "+Int2Str(sendBytes)+ " bytes "); } } @@ -118,14 +118,14 @@ bool TLMCommUtil::ReceiveMessage(TLMMessage& mess) { int errcode=WSAGetLastError(); if(errcode==WSAECONNRESET) // This is called by normal termination of BEAST - TLMErrorLog::Log("SOCKET_ERROR received, error code ="+Int2Str(errcode)); + TLMErrorLog::Info("SOCKET_ERROR received, error code ="+Int2Str(errcode)); else TLMErrorLog::Warning("SOCKET_ERROR received, error code ="+Int2Str(errcode)); #endif return false; } if(doDetailedLogging) { - TLMErrorLog::Log("ReceiveMessage:recv() returned "+Int2Str(bcount)+ " bytes "); + TLMErrorLog::Info("ReceiveMessage:recv() returned "+Int2Str(bcount)+ " bytes "); } if(strncmp(mess.Header.Signature, TLMMessageHeader::TLMSignature, TLMMessageHeader::TLM_SIGNATURE_LENGTH) != 0) { @@ -173,7 +173,7 @@ bool TLMCommUtil::ReceiveMessage(TLMMessage& mess) { return false; } if(doDetailedLogging) { - TLMErrorLog::Log("ReceiveMessage:recv()(part 2) returned "+Int2Str(bcount)+ " bytes "); + TLMErrorLog::Info("ReceiveMessage:recv()(part 2) returned "+Int2Str(bcount)+ " bytes "); } if(bcount != mess.Header.DataSize) { TLMErrorLog::FatalError("Error receiving message data"); diff --git a/common/Communication/TLMManagerComm.cc b/common/Communication/TLMManagerComm.cc index a04aa75..386c950 100644 --- a/common/Communication/TLMManagerComm.cc +++ b/common/Communication/TLMManagerComm.cc @@ -115,7 +115,7 @@ int TLMManagerComm::CreateServerSocket() { ContactSocket = theSckt; - TLMErrorLog::Log(string("TLM manager is listening on port ") + TLMErrorLog::ToStdStr(ServerPort)); + TLMErrorLog::Info(string("TLM manager is listening on port ") + TLMErrorLog::ToStdStr(ServerPort)); return theSckt; } @@ -166,7 +166,7 @@ void TLMManagerComm::SwitchToRunningMode() { } int TLMManagerComm::AcceptComponentConnections() { - TLMErrorLog::Log("TLM_manager - accepting connection"); + TLMErrorLog::Info("TLM_manager - accepting connection"); int theCon; if((theCon = accept(ContactSocket,NULL,NULL)) < 0) { TLMErrorLog::FatalError("Could not accept a connection"); diff --git a/common/CompositeModels/CompositeModel.cc b/common/CompositeModels/CompositeModel.cc index e71e7cc..b04e4fc 100644 --- a/common/CompositeModels/CompositeModel.cc +++ b/common/CompositeModels/CompositeModel.cc @@ -175,7 +175,7 @@ CompositeModel::~CompositeModel() { bool CompositeModel::CheckTheModel() { - TLMErrorLog::Log("Checking model..."); + TLMErrorLog::Info("Checking model..."); bool abort=false; @@ -283,7 +283,7 @@ int CompositeModel::RegisterTLMInterfaceProxy(const int ComponentID, string& Nam TLMInterfaceProxy* ifc = new TLMInterfaceProxy(ComponentID, Interfaces.size(), Name, Dimensions, Causality, Domain); - TLMErrorLog::Log("Registering interface proxy." + TLMErrorLog::Info("Registering interface proxy." " Id = "+TLMErrorLog::ToStdStr(int(Interfaces.size()))+ ", ComponentId = "+TLMErrorLog::ToStdStr(ComponentID)+ ", Name = " + Name+ @@ -298,7 +298,7 @@ int CompositeModel::RegisterTLMInterfaceProxy(const int ComponentID, string& Nam int CompositeModel::RegisterComponentParameterProxy(const int ComponentID, string& Name, string& DefaultValue) { ComponentParameterProxy* par = new ComponentParameterProxy(ComponentID, ComponentParameters.size(), Name, DefaultValue); - TLMErrorLog::Log("Registering parameter proxy." + TLMErrorLog::Info("Registering parameter proxy." " Id = " + TLMErrorLog::ToStdStr(int(ComponentParameters.size()))+ ", ComponentId = "+TLMErrorLog::ToStdStr(ComponentID)+ ", Name = " + Name+ @@ -347,23 +347,23 @@ int CompositeModel::RegisterTLMConnection(int ifc1, int ifc2, TLMConnectionParam // Start components void CompositeModel::StartComponents() { for(unsigned i = 0; i < Components.size(); i++) { - TLMErrorLog::Log(string("----- Starting External Tool ----- ")); - TLMErrorLog::Log("Name: "+Components[i]->GetName()); + TLMErrorLog::Info(string("----- Starting External Tool ----- ")); + TLMErrorLog::Info("Name: "+Components[i]->GetName()); double maxStep = 1e150; for(unsigned j = 0; j < Interfaces.size(); j++) { // check that the interface belongs to this component if((unsigned)Interfaces[j]->GetComponentID() != i) { - TLMErrorLog::Log("Wrong component ID."); + TLMErrorLog::Info("Wrong component ID."); continue; } // check that interface is connected int conID = Interfaces[j]->GetConnectionID(); if(conID < 0) { - TLMErrorLog::Log("Interface not connected."); + TLMErrorLog::Info("Interface not connected."); continue; } - TLMErrorLog::Log("Found interface: "+Interfaces[j]->GetName()); + TLMErrorLog::Info("Found interface: "+Interfaces[j]->GetName()); TLMConnection& conn = GetTLMConnection(conID); @@ -371,7 +371,7 @@ void CompositeModel::StartComponents() { maxStep = conn.GetParams().Delay; } - TLMErrorLog::Log("Connection delay = "+TLMErrorLog::ToStdStr(conn.GetParams().Delay)); + TLMErrorLog::Info("Connection delay = "+TLMErrorLog::ToStdStr(conn.GetParams().Delay)); } if(1e150 == maxStep) maxStep = 0; if(maxStep <= 0) { @@ -383,7 +383,7 @@ void CompositeModel::StartComponents() { if(!Components[i]->GetSolverMode()) maxStep /= 2; - TLMErrorLog::Log(string("Choosing the max time step for ")+ + TLMErrorLog::Info(string("Choosing the max time step for ")+ Components[i]->GetName() + " " + TLMErrorLog::ToStdStr(maxStep)); @@ -394,20 +394,20 @@ void CompositeModel::StartComponents() { bool CompositeModel::CheckProxyComm() { for(ComponentsVector::iterator it = Components.begin(); it!=Components.end(); ++it) { if(((*it)->GetSocketHandle() < 0) || !(*it)->GetReadyToSim()) { - TLMErrorLog::Log(string("Component ") + (*it)->GetName() + " is not ready for simulation"); + TLMErrorLog::Info(string("Component ") + (*it)->GetName() + " is not ready for simulation"); return false; } } for(TLMInterfacesVector::iterator it = Interfaces.begin(); it != Interfaces.end(); it++) { if(!(*it)->GetConnected()) { - TLMErrorLog::Log("TLM interface " + GetTLMComponentProxy((*it)->GetComponentID()).GetName() + '.' + TLMErrorLog::Info("TLM interface " + GetTLMComponentProxy((*it)->GetComponentID()).GetName() + '.' + (*it)->GetName() + " is not registered by the component."); return false; } } - TLMErrorLog::Log("Meta model checking completed successfully"); + TLMErrorLog::Info("Meta model checking completed successfully"); return true; } @@ -462,7 +462,7 @@ std::string GetLastErrorStdStr() { #endif // Start the component executable void TLMComponentProxy::StartComponent(SimulationParams& SimParams, double MaxStep) { - TLMErrorLog::Log(string("Starting ") + StartCommand); + TLMErrorLog::Info(string("Starting ") + StartCommand); // In the special case where start-command is explicitely set to "none" // we skip startup. This is useful for integrated simulation/tlm-manager. @@ -494,13 +494,13 @@ void TLMComponentProxy::StartComponent(SimulationParams& SimParams, double MaxSt command << " " << strMaxStep.c_str(); command << " " << serverName.c_str(); command << " " << ModelName.c_str(); - TLMErrorLog::Log(string("Starting ") + command.str()); + TLMErrorLog::Info(string("Starting ") + command.str()); if(!CreateProcessA(NULL, (char *)command.str().c_str(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { TLMErrorLog::FatalError("StartComponent: Failed to start the component " + Name + " with command " + StartCommand + "." "Error is " + GetLastErrorStdStr()); exit(-1); } else { - TLMErrorLog::Log(string("CreateProcessA Success")); + TLMErrorLog::Info(string("CreateProcessA Success")); } // Close process and thread handles. @@ -559,7 +559,7 @@ void TLMComponentProxy::StartComponent(SimulationParams& SimParams, double MaxSt #endif } else { - TLMErrorLog::Log("Start command \"none\" nothing started!"); + TLMErrorLog::Info("Start command \"none\" nothing started!"); } } diff --git a/common/CompositeModels/CompositeModelReader.cc b/common/CompositeModels/CompositeModelReader.cc index 95876f4..0e36256 100644 --- a/common/CompositeModels/CompositeModelReader.cc +++ b/common/CompositeModels/CompositeModelReader.cc @@ -32,8 +32,8 @@ void CompositeModelReader::ReadComponents(xmlNode *node, bool skipInterfaces=fal continue; //Don't load other models than the single model } - TLMErrorLog::Log(string("----- Processing SubModel ----- ")); - TLMErrorLog::Log("Name: "+Name); + TLMErrorLog::Info(string("----- Processing SubModel ----- ")); + TLMErrorLog::Info("Name: "+Name); curAttrVal = FindAttributeByName(curNode, "StartCommand"); string StartCommand((const char*)curAttrVal->content); @@ -233,7 +233,7 @@ void CompositeModelReader::ReadPositionAndOrientation(xmlNode* node, double R[3] // from XML-element node for a TLMConnection void CompositeModelReader::ReadSimParams(xmlNode* node) { - TLMErrorLog::Log(string("----- Reading simulation parameters ----- ")); + TLMErrorLog::Info(string("----- Reading simulation parameters ----- ")); xmlNode* curAttrVal = FindAttributeByName(node, "ManagerPort", false); int Port = 11111; // Some default port. @@ -265,9 +265,9 @@ void CompositeModelReader::ReadSimParams(xmlNode* node) { TheModel.GetSimParams().Set(Port, StartTime, StopTime); TheModel.GetSimParams().SetWriteTimeStep(WriteTimeStep); - TLMErrorLog::Log("StartTime = "+TLMErrorLog::ToStdStr(StartTime)+" s"); - TLMErrorLog::Log("StopTime = "+TLMErrorLog::ToStdStr(StopTime)+" s"); - TLMErrorLog::Log("WriteTimeStep = "+TLMErrorLog::ToStdStr(WriteTimeStep)+" s"); + TLMErrorLog::Info("StartTime = "+TLMErrorLog::ToStdStr(StartTime)+" s"); + TLMErrorLog::Info("StopTime = "+TLMErrorLog::ToStdStr(StopTime)+" s"); + TLMErrorLog::Info("WriteTimeStep = "+TLMErrorLog::ToStdStr(WriteTimeStep)+" s"); } @@ -313,18 +313,18 @@ xmlNode* CompositeModelReader::FindAttributeByName(xmlNode* node, const char* na // result of the method. void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { - TLMErrorLog::Log(string("Reading definition for Connections ")); + TLMErrorLog::Info(string("Reading definition for Connections ")); if(node != 0) { for(xmlNode* curNode = node->children; curNode; curNode = curNode->next) { if( (XML_ELEMENT_NODE == curNode->type) && (strcmp("Connection", (const char*)curNode->name) == 0) ) { - TLMErrorLog::Log(string("----- Processing Connection ----- ")); + TLMErrorLog::Info(string("----- Processing Connection ----- ")); // Read connection attributes: xmlNode* curAttr = FindAttributeByName(curNode, "From"); string AttrData((const char*)curAttr->content); - TLMErrorLog::Log(string("From:") + AttrData); + TLMErrorLog::Info(string("From:") + AttrData); int fromID, toID; TLMConnectionParams conParam; @@ -338,7 +338,7 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { curAttr = FindAttributeByName(curNode, "To"); AttrData = (const char*)curAttr->content; - TLMErrorLog::Log(string("To:") + AttrData); + TLMErrorLog::Info(string("To:") + AttrData); toID = TheModel.GetTLMInterfaceID(AttrData); if(toID < 0) { TLMErrorLog::FatalError(string("Could not find definition for interface ") @@ -351,12 +351,12 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { curAttr = FindAttributeByName(curNode, "Delay"); conParam.Delay = atof((const char*)curAttr->content); - TLMErrorLog::Log("Delay = "+TLMErrorLog::ToStdStr(conParam.Delay)+" s"); + TLMErrorLog::Info("Delay = "+TLMErrorLog::ToStdStr(conParam.Delay)+" s"); if(fromIfc.GetCausality() == "Bidirectional") { curAttr = FindAttributeByName(curNode, "Zf"); conParam.Zf = atof((const char*)curAttr->content); - TLMErrorLog::Log("Zf = "+TLMErrorLog::ToStdStr(conParam.Zf)); + TLMErrorLog::Info("Zf = "+TLMErrorLog::ToStdStr(conParam.Zf)); } if(fromIfc.GetCausality() == "Bidirectional" && fromIfc.GetDimensions() > 1) { @@ -368,7 +368,7 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { TLMErrorLog::Warning(string("No impedance for rotation (Zfr) is defined, Zf will be used")); conParam.Zfr = conParam.Zf; } - TLMErrorLog::Log("Zf = "+TLMErrorLog::ToStdStr(conParam.Zfr)); + TLMErrorLog::Info("Zf = "+TLMErrorLog::ToStdStr(conParam.Zfr)); } if(fromIfc.GetCausality() == "Bidirectional") { @@ -380,7 +380,7 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { TLMErrorLog::Warning(string("No damping coefficient (alpha) is defined, assume no damping")); conParam.alpha = 0.0; } - TLMErrorLog::Log("alpha = "+TLMErrorLog::ToStdStr(conParam.alpha)); + TLMErrorLog::Info("alpha = "+TLMErrorLog::ToStdStr(conParam.alpha)); } int conID = TheModel.RegisterTLMConnection(fromID, toID, conParam); @@ -392,7 +392,7 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { } } else { - TLMErrorLog::Log(string("No connections found, continue anyway.")); + TLMErrorLog::Info(string("No connections found, continue anyway.")); } } // ReadTLMConnectionNode(xmlNode* node) @@ -403,7 +403,7 @@ void CompositeModelReader::ReadTLMConnectionNode(xmlNode* node) { // Input/Output: TheModel - model structure to be build. void CompositeModelReader::ReadModel(std::string &InputFile, bool InterfaceRequestMode, std::string singleModel) { - TLMErrorLog::Log("---------------------- Reading composite model ---------------------- "); + TLMErrorLog::Info("---------------------- Reading composite model ---------------------- "); xmlDoc* doc = xmlParseFile(InputFile.c_str()); // open XML & parse it if(doc == NULL) { @@ -412,7 +412,7 @@ void CompositeModelReader::ReadModel(std::string &InputFile, bool InterfaceReque xmlNode *model_element = xmlDocGetRootElement(doc); // get root element - TLMErrorLog::Log("XML file is parsed OK. Creating model."); + TLMErrorLog::Info("XML file is parsed OK. Creating model."); xmlNode *components = FindChildByName(model_element, "SubModels"); //Don't load interfaces in interface request mode @@ -429,7 +429,7 @@ void CompositeModelReader::ReadModel(std::string &InputFile, bool InterfaceReque ReadSimParams(sim_params); - TLMErrorLog::Log("---------------------- Composite model is read ---------------------- "); + TLMErrorLog::Info("---------------------- Composite model is read ---------------------- "); // free the document and the global vars xmlFreeDoc(doc); diff --git a/common/Interfaces/TLMInterface.cc b/common/Interfaces/TLMInterface.cc index 2ec087c..a6821e0 100644 --- a/common/Interfaces/TLMInterface.cc +++ b/common/Interfaces/TLMInterface.cc @@ -47,7 +47,7 @@ TLMInterface::TLMInterface(TLMClientComm& theComm, std::string& aName, double St } InterfaceID = Message.Header.TLMInterfaceID; - TLMErrorLog::Log(std::string("Interface ") + GetName() + " got ID " + TLMErrorLog::ToStdStr(InterfaceID)); + TLMErrorLog::Info(std::string("Interface ") + GetName() + " got ID " + TLMErrorLog::ToStdStr(InterfaceID)); Comm.UnpackRegInterfaceMessage(Message, Params); diff --git a/common/Interfaces/TLMInterface1D.cc b/common/Interfaces/TLMInterface1D.cc index b0edda5..af45d32 100644 --- a/common/Interfaces/TLMInterface1D.cc +++ b/common/Interfaces/TLMInterface1D.cc @@ -14,7 +14,7 @@ TLMInterface1D::TLMInterface1D(TLMClientComm &theComm, std::string &aName, doubl TLMInterface1D::~TLMInterface1D() { if(DataToSend.size() != 0) { - TLMErrorLog::Log(std::string("Interface ") + GetName() + " sends rest of data for time= " + + TLMErrorLog::Info(std::string("Interface ") + GetName() + " sends rest of data for time= " + TLMErrorLog::ToStdStr(DataToSend.back().time)); Comm.PackTimeDataMessage1D(InterfaceID, DataToSend, Message); @@ -94,8 +94,10 @@ void TLMInterface1D::GetTimeData(TLMTimeData1D& Instance, std::deque= TLMLogLevel::Info) { + TLMErrorLog::Info(std::string("Interface ") + GetName() + + " SET for time= " + TLMErrorLog::ToStdStr(time) + // + " force:" + // + TLMErrorLog::ToStdStr(item.GenForce[0])+ ", " + // + TLMErrorLog::ToStdStr(item.GenForce[1])+ ", " + // + TLMErrorLog::ToStdStr(item.GenForce[2])+ ", " + // + " position:" + // + TLMErrorLog::ToStdStr(item.Position[0])+ ", " + // + TLMErrorLog::ToStdStr(item.Position[1])+ ", " + // + TLMErrorLog::ToStdStr(item.Position[2])+ ", " + // + "torque: " + // + TLMErrorLog::ToStdStr(item.GenForce[3])+ ", " + // + TLMErrorLog::ToStdStr(item.GenForce[4])+ ", " + // + TLMErrorLog::ToStdStr(item.GenForce[5])); + ); + } // Send the data if we past the synchronization point or are in data request mode. if(time >= LastSendTime + Params.Delay / 2 || Params.mode > 0.0) { @@ -300,8 +302,10 @@ void TLMInterface3D::TransformTimeDataToCG(std::vector& timeData, void TLMInterface3D::SendAllData() { LastSendTime = DataToSend.back().time; - TLMErrorLog::Log(std::string("Interface ") + GetName() + " sends data for time= " + - TLMErrorLog::ToStdStr(LastSendTime)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(std::string("Interface ") + GetName() + " sends data for time= " + + TLMErrorLog::ToStdStr(LastSendTime)); + } // Transform to global inertial system cG ans send TransformTimeDataToCG(DataToSend, Params); diff --git a/common/Interfaces/TLMInterfaceSignal.cc b/common/Interfaces/TLMInterfaceSignal.cc index db9414e..3c06ef7 100644 --- a/common/Interfaces/TLMInterfaceSignal.cc +++ b/common/Interfaces/TLMInterfaceSignal.cc @@ -27,8 +27,10 @@ void TLMInterfaceSignal::UnpackTimeData(TLMMessage &mess) { void TLMInterfaceSignal::SendAllData() { LastSendTime = DataToSend.back().time; - TLMErrorLog::Log(std::string("Interface ") + GetName() + " sends data for time= " + - TLMErrorLog::ToStdStr(LastSendTime)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(std::string("Interface ") + GetName() + " sends data for time= " + + TLMErrorLog::ToStdStr(LastSendTime)); + } Comm.PackTimeDataMessageSignal(InterfaceID, DataToSend, Message); TLMCommUtil::SendMessage(Message); diff --git a/common/Interfaces/TLMInterfaceSignalOutput.cc b/common/Interfaces/TLMInterfaceSignalOutput.cc index 2a9e96f..3ce60fd 100644 --- a/common/Interfaces/TLMInterfaceSignalOutput.cc +++ b/common/Interfaces/TLMInterfaceSignalOutput.cc @@ -14,8 +14,10 @@ TLMInterfaceOutput::TLMInterfaceOutput(TLMClientComm &theComm, std::string &aNam TLMInterfaceOutput::~TLMInterfaceOutput() { if(DataToSend.size() != 0) { - TLMErrorLog::Log(std::string("Interface ") + GetName() + " sends rest of data for time= " + - TLMErrorLog::ToStdStr(DataToSend.back().time)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(std::string("Interface ") + GetName() + " sends rest of data for time= " + + TLMErrorLog::ToStdStr(DataToSend.back().time)); + } Comm.PackTimeDataMessageSignal(InterfaceID, DataToSend, Message); TLMCommUtil::SendMessage(Message); @@ -33,8 +35,10 @@ void TLMInterfaceOutput::SetTimeData(double time, item.time = time; item.Value = value; - TLMErrorLog::Log(std::string("Interface ") + GetName() + - " SET for time= " + TLMErrorLog::ToStdStr(time)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(std::string("Interface ") + GetName() + + " SET for time= " + TLMErrorLog::ToStdStr(time)); + } // Send the data if we past the synchronization point or are in data request mode. if(time >= LastSendTime + Params.Delay / 2 || Params.mode > 0.0 ) { diff --git a/common/Logging/TLMErrorLog.cc b/common/Logging/TLMErrorLog.cc index c129b11..19e4122 100644 --- a/common/Logging/TLMErrorLog.cc +++ b/common/Logging/TLMErrorLog.cc @@ -40,8 +40,8 @@ void _strtime(char* timestring) { #endif -bool TLMErrorLog::LoggingOn = false; -bool TLMErrorLog::WarningOn = false; + +TLMLogLevel TLMErrorLog::LogLevel = TLMLogLevel::Fatal; bool TLMErrorLog::ExceptionOn = false; bool TLMErrorLog::NormalErrorLogOn = false; bool TLMErrorLog::LogTimeOn = false; @@ -55,11 +55,6 @@ void TLMErrorLog::Open() { } } -void TLMErrorLog::SetDebugOut(bool Enable) { - - LoggingOn = Enable; - if(Enable) Log("Logging is enabled in TLMErrorLog::SetDebugOut"); -} // FatalError function writes a message to log file // then terminates the program abnormally. @@ -89,59 +84,56 @@ void TLMErrorLog::FatalError(const std::string& mess) { // Warning function prints a warning message to log file // void TLMErrorLog::Warning(const std::string& mess) { + if(LogLevel < TLMLogLevel::Warning) return; + Open(); + std::cout << TimeStr() << " Warning: " << mess << std::endl; + *outStream << TimeStr() << " Warning: " << mess << std::endl; - if(WarningOn) { - Open(); - std::cout << TimeStr() << " Warning: " << mess << std::endl; - *outStream << TimeStr() << " Warning: " << mess << std::endl; - - if(NormalErrorLogOn) { - _strtime(tmpbuf); + if(NormalErrorLogOn) { + _strtime(tmpbuf); #ifdef USE_ERRORLOG - ::Warning("TMLLog:"+Bstring(tmpbuf)+" "+mess); + ::Warning("TMLLog:"+Bstring(tmpbuf)+" "+mess); #endif - } - } } // Log function logs a message to log file -void TLMErrorLog::Log(const std::string& mess) { - - if(!LoggingOn) return; +void TLMErrorLog::Info(const std::string& mess) { + if(LogLevel < TLMLogLevel::Info) return; Open(); - *outStream << TimeStr() << " Log: " << mess << std::endl; + *outStream << TimeStr() << " Info: " << mess << std::endl; if(NormalErrorLogOn) { _strtime(tmpbuf); #ifdef USE_ERRORLOG Log1("TMLLog:"+Bstring(tmpbuf)+" "+mess); #endif } - } -// A utility function often used to log numerical information -std::string TLMErrorLog::ToStdStr(double val) { - if(!NormalErrorLogOn) { - return ""; + +// Log function logs a message to log file +void TLMErrorLog::Debug(const std::string& mess) { + if(LogLevel < TLMLogLevel::Debug) return; + Open(); + *outStream << TimeStr() << " Debug: " << mess << std::endl; + if(NormalErrorLogOn) { + _strtime(tmpbuf); +#ifdef USE_ERRORLOG + Log1("TMLLog:"+Bstring(tmpbuf)+" "+mess); +#endif } - char buf[30]; +} - sprintf(buf, "%.10f", val); - return std::string(buf); +// A utility function often used to log numerical information +std::string TLMErrorLog::ToStdStr(double val) { + TLMErrorLog::Debug("Debug 1."); + return std::to_string(val); } // A utility function often used to log numerical information std::string TLMErrorLog::ToStdStr(int val) { - if(!NormalErrorLogOn) { - return ""; - } - char buf[30]; - - sprintf(buf, "%d", val); - - return std::string(buf); + return std::to_string(val); } std::string TLMErrorLog::TimeStr() { diff --git a/common/Logging/TLMErrorLog.h b/common/Logging/TLMErrorLog.h index f97b502..3a1bbb5 100644 --- a/common/Logging/TLMErrorLog.h +++ b/common/Logging/TLMErrorLog.h @@ -15,6 +15,8 @@ #include #include +enum TLMLogLevel { Fatal, Warning, Info, Debug }; + //! Error handling is implemented in the most simple way //! with the functions that write messages to standard error output (cerr). //! In addition FatalError calls abort() to terminate the application. @@ -30,21 +32,22 @@ class TLMErrorLog { //! Warning function prints a warning message to standard error output static void Warning(const std::string& mess); - //! Log function logs a message to standard error output - static void Log(const std::string& mess); + //! Info function logs an info message to standard error output + static void Info(const std::string& mess); + + //! Debug function logs a debug message to standard error output + static void Debug(const std::string& mess); //! Utility functions often used to log numerical information static std::string ToStdStr(double val); static std::string ToStdStr(int val); - //! LogEnabled returnes the value of LoggingOn flag. Used for checking - //! if logging is enabled. - static bool LogEnabled() { return LoggingOn; } - //! SetDebugOut function enables/disables debug information //! output from TLM plugin. //! Input: if Enable is true - output is on, othewise - off. - static void SetDebugOut(bool Enable); + static void SetLogLevel(TLMLogLevel logLevel) { LogLevel = logLevel; } + + static TLMLogLevel GetLogLevel() { return LogLevel; } //! This function enables so that logs are duplicated to the normal *.log file as well. //! Input: if Enable is true - output is on, othewise - off. @@ -52,10 +55,6 @@ class TLMErrorLog { static bool IsNormalErrorLogOn() { return NormalErrorLogOn; } - //! This function enables/disables warning messages - //! Input: if Enable is true - output is on, othewise - off. - static void SetWarningOut(bool Enable) { WarningOn = Enable; } - //! Sets the output stream for output of all log, warning, and error messages. //! Default output stream id std::cout static void SetOutStream(std::ostream& of) { outStream = &of; } @@ -72,11 +71,8 @@ class TLMErrorLog { static std::string TimeStr(); private: - //! LoggingOn flags tells if logging is enabled. - static bool LoggingOn; - - //! Warning messages on if enabled. - static bool WarningOn; + //! LogLevel specifies level of logging to be used + static TLMLogLevel LogLevel; //! Exception mode on in enabled. //! See also SetErrorException(...). diff --git a/common/ManagerMain.cc b/common/ManagerMain.cc index 157035b..f13e9b5 100644 --- a/common/ManagerMain.cc +++ b/common/ManagerMain.cc @@ -30,8 +30,8 @@ void usage() { "-m : set the port for monitoring connections\n" "-p : set the server network port for communication with the simulation tools\n" "-r : run manager in interface request mode, get information about interface locations"; - TLMErrorLog::SetDebugOut(true); - TLMErrorLog::Log(usageStr); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); + TLMErrorLog::Info(usageStr); std::cout << usageStr << std::endl; exit(1); } @@ -154,8 +154,7 @@ int main(int argc, char* argv[]) { // Debug on? if(debugFlg || comMode == ManagerCommHandler::InterfaceRequestMode) { //Always enable debug for interface request /robbr - TLMErrorLog::SetDebugOut(true); - TLMErrorLog::SetWarningOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); } // Create the meta model object diff --git a/common/MonitorMain.cc b/common/MonitorMain.cc index e38c512..15518c8 100644 --- a/common/MonitorMain.cc +++ b/common/MonitorMain.cc @@ -30,8 +30,8 @@ using std::string; void usage() { string usageStr = "Usage: tlmmonitor [-d] [-n num-seps | -t time-step-size] , where compositemodel is an XML file."; - TLMErrorLog::SetDebugOut(true); - TLMErrorLog::Log(usageStr); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); + TLMErrorLog::Info(usageStr); std::cout << usageStr << std::endl; exit(1); } @@ -50,7 +50,7 @@ struct Color { TLMPlugin* InitializeTLMConnection(CompositeModel& model, std::string& serverName) { TLMPlugin* TLMlink = MonitoringPluginImplementer::CreateInstance(); - TLMErrorLog::Log("Trying to register TLM monitor on host " + serverName); + TLMErrorLog::Info("Trying to register TLM monitor on host " + serverName); if(! TLMlink->Init("monitor", model.GetSimParams().GetStartTime(), @@ -67,16 +67,16 @@ TLMPlugin* InitializeTLMConnection(CompositeModel& model, std::string& serverNam TLMInterfaceProxy& interfaceProxy = model.GetTLMInterfaceProxy(i); TLMComponentProxy& component = model.GetTLMComponentProxy(interfaceProxy.GetComponentID()); - TLMErrorLog::Log("Trying to register monitoring interface " + interfaceProxy.GetName()); + TLMErrorLog::Info("Trying to register monitoring interface " + interfaceProxy.GetName()); int TLMInterfaceID = TLMlink->RegisteTLMInterface(component.GetName() + "." + interfaceProxy.GetName(), interfaceProxy.GetDimensions(), interfaceProxy.GetCausality(), interfaceProxy.GetDomain()); if(TLMInterfaceID >= 0) { - TLMErrorLog::Log("Registration was successful"); + TLMErrorLog::Info("Registration was successful"); } else { - TLMErrorLog::Log("Interface not connected in Meta-Model: " + component.GetName() + "." + interfaceProxy.GetName()); + TLMErrorLog::Info("Interface not connected in Meta-Model: " + component.GetName() + "." + interfaceProxy.GetName()); } } @@ -101,8 +101,8 @@ void MonitorTimeStep(TLMPlugin* TLMlink, int dimensions = interfaceProxy.GetDimensions(); string causality = interfaceProxy.GetCausality(); - if(TLMErrorLog::IsNormalErrorLogOn()) { - TLMErrorLog::Log("Data request for " + interfaceProxy.GetName() + " for time " + ToStr(SimTime) + ", id: " + ToStr(interfaceID)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info("Data request for " + interfaceProxy.GetName() + " for time " + ToStr(SimTime) + ", id: " + ToStr(interfaceID)); } if(connectionID >= 0) { @@ -501,7 +501,7 @@ void PrintData(CompositeModel& model, if(interfaceProxy.GetDimensions() == 6) { std::stringstream ss; ss << "Printing data for 3D interface " << interfaceProxy.GetID(); - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); TLMTimeData3D& timeData = dataStorage3D.at(interfaceProxy.GetID()); @@ -560,7 +560,7 @@ void PrintData(CompositeModel& model, interfaceProxy.GetCausality() == "Bidirectional") { std::stringstream ss; ss << "Printing data for 1D interface " << interfaceProxy.GetID(); - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); TLMTimeData1D& timeData = dataStorage1D.at(interfaceProxy.GetID()); @@ -615,7 +615,7 @@ void PrintData(CompositeModel& model, std::stringstream ss; ss << "Printing data for output interface " << interfaceProxy.GetID(); - TLMErrorLog::Log(ss.str()); + TLMErrorLog::Info(ss.str()); TLMTimeDataSignal& timeData = dataStorageSignal.at(interfaceProxy.GetID()); @@ -674,7 +674,7 @@ void PrintRunStatus(CompositeModel& model, std::ofstream& runFile, tTM_Info& tIn int main(int argc, char* argv[]) { - TLMErrorLog::Log("Starting monitor..."); + TLMErrorLog::Info("Starting monitor..."); #ifndef USE_THREADS #warning TLM manager requires pthreads to be compiled in. Use -DUSE_THREADS in the Makefile.head if neeeded. @@ -714,9 +714,8 @@ int main(int argc, char* argv[]) { logfile.open("monitor.log"); TLMErrorLog::SetOutStream(logfile); if(debugFlg) { - TLMErrorLog::SetDebugOut(true); + TLMErrorLog::SetLogLevel(TLMLogLevel::Debug); TLMErrorLog::SetNormalErrorLogOn(true); - TLMErrorLog::SetWarningOut(true); } // Get input strings, server name and meta-model XML file. diff --git a/common/Parameters/ComponentParameter.cc b/common/Parameters/ComponentParameter.cc index 1f280ac..3b1af28 100644 --- a/common/Parameters/ComponentParameter.cc +++ b/common/Parameters/ComponentParameter.cc @@ -33,7 +33,7 @@ ComponentParameter::ComponentParameter(TLMClientComm& theComm, std::string& aNam Comm.UnpackRegParameterMessage(Message, Value); - TLMErrorLog::Log(std::string("Parameter ") + GetName() + " got ID " + TLMErrorLog::ToStdStr(ParameterID)); + TLMErrorLog::Info(std::string("Parameter ") + GetName() + " got ID " + TLMErrorLog::ToStdStr(ParameterID)); } diff --git a/common/Plugin/MonitoringPluginImplementer.cc b/common/Plugin/MonitoringPluginImplementer.cc index b9a3516..d6586a9 100644 --- a/common/Plugin/MonitoringPluginImplementer.cc +++ b/common/Plugin/MonitoringPluginImplementer.cc @@ -16,9 +16,12 @@ void MonitoringPluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double t while(time > reqIfc->GetNextRecvTime()) { // while data is needed // Receive data untill there is info for this interface - string mess("Interface "); - TLMErrorLog::Log(mess + reqIfc->GetName() + - " needs data for time= " + TLMErrorLog::ToStdStr(time)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info("Interface " + + reqIfc->GetName() + + " needs data for time= " + + TLMErrorLog::ToStdStr(time)); + } TLMInterface* ifc = NULL; @@ -39,8 +42,8 @@ void MonitoringPluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double t ifc->UnpackTimeData(Message); // Received data - if(TLMErrorLog::IsNormalErrorLogOn()) { - TLMErrorLog::Log(string("Interface ") + ifc->GetName() + " got data until time= " + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(string("Interface ") + ifc->GetName() + " got data until time= " + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); } @@ -48,7 +51,7 @@ void MonitoringPluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double t if(ifc == NULL) break; // receive error - breaking - TLMErrorLog::Log(string("Got data until time=") + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); + TLMErrorLog::Info(string("Got data until time=") + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); } } diff --git a/common/Plugin/PluginImplementer.cc b/common/Plugin/PluginImplementer.cc index 50ece23..debfc16 100644 --- a/common/Plugin/PluginImplementer.cc +++ b/common/Plugin/PluginImplementer.cc @@ -24,13 +24,13 @@ TLMPlugin* TLMPlugin::CreateInstance() { void PluginImplementer::AwaitClosePermission() { - TLMErrorLog::Log("Awaiting close permission..."); + TLMErrorLog::Info("Awaiting close permission..."); Message.Header.MessageType = TLMMessageTypeConst::TLM_CLOSE_REQUEST; TLMCommUtil::SendMessage(Message); while(Message.Header.MessageType != TLMMessageTypeConst::TLM_CLOSE_PERMISSION) { TLMCommUtil::ReceiveMessage(Message); } - TLMErrorLog::Log("Close permission received."); + TLMErrorLog::Info("Close permission received."); } void PluginImplementer::SetInitialForce3D(int interfaceID, double f1, double f2, double f3, double t1, double t2, double t3) @@ -115,7 +115,7 @@ void PluginImplementer::HandleSignal(int signum) { TLMCommUtil::SendMessage(Message); } - TLMErrorLog::Log("Got signal " + TLMErrorLog::ToStdStr(signum)); + TLMErrorLog::Info("Got signal " + TLMErrorLog::ToStdStr(signum)); } void PluginImplementer::CheckModel() { @@ -130,7 +130,7 @@ void PluginImplementer::CheckModel() { TLMCommUtil::ReceiveMessage(Message); if(! Message.Header.TLMInterfaceID) { - TLMErrorLog::Log("Error detected on TLM manager while checking meta model"); + TLMErrorLog::Info("Error detected on TLM manager while checking meta model"); TLMErrorLog::FatalError("Header id is " + TLMErrorLog::ToStdStr(int(Message.Header.TLMInterfaceID))); } @@ -165,13 +165,13 @@ bool PluginImplementer::Init(std::string model, return false; } - TLMErrorLog::Log("Sending Component registration request"); + TLMErrorLog::Info("Sending Component registration request"); ClientComm.CreateComponentRegMessage(model, Message); TLMCommUtil::SendMessage(Message); TLMCommUtil::ReceiveMessage(Message); - TLMErrorLog::Log(string("Got component ID: ") + + TLMErrorLog::Info(string("Got component ID: ") + TLMErrorLog::ToStdStr(Message.Header.TLMInterfaceID)); StartTime = timeStart; @@ -190,23 +190,23 @@ bool PluginImplementer::Init(std::string model, // the interface is not connected in the CompositeModel. int PluginImplementer::RegisteTLMInterface(std::string name , int dimensions, std::string causality, std::string domain) { - TLMErrorLog::Log(string("Register Interface ") + name); + TLMErrorLog::Info(string("Register Interface ") + name); TLMInterface *ifc; if(dimensions==6) { - TLMErrorLog::Log("Registers TLM interface of type 3D"); + TLMErrorLog::Info("Registers TLM interface of type 3D"); ifc = new TLMInterface3D(ClientComm, name, StartTime, domain); } else if(dimensions == 1 && causality == "Bidirectional") { - TLMErrorLog::Log("Registers TLM interface of type 1D"); + TLMErrorLog::Info("Registers TLM interface of type 1D"); ifc = new TLMInterface1D(ClientComm, name, StartTime, domain); } else if(dimensions == 1 && causality == "Input") { - TLMErrorLog::Log("Registers TLM interface of type SignalInput"); + TLMErrorLog::Info("Registers TLM interface of type SignalInput"); ifc = new TLMInterfaceInput(ClientComm, name, StartTime, domain); } else if(dimensions == 1 && causality == "Output") { - TLMErrorLog::Log("Registers TLM interface of type SignalOutput"); + TLMErrorLog::Info("Registers TLM interface of type SignalOutput"); ifc = new TLMInterfaceOutput(ClientComm, name, StartTime, domain); } else { @@ -215,7 +215,7 @@ int PluginImplementer::RegisteTLMInterface(std::string name , int dimensions, int id = ifc->GetInterfaceID(); - TLMErrorLog::Log(string("Got interface ID: ") + TLMErrorLog::ToStdStr(id)); + TLMErrorLog::Info(string("Got interface ID: ") + TLMErrorLog::ToStdStr(id)); // Check that this interface is connected if(id < 0) { @@ -240,7 +240,7 @@ int PluginImplementer::RegisterComponentParameter(std::string name, std::string int id = par->GetParameterID(); - TLMErrorLog::Log(string("Got parameter ID: ") + TLMErrorLog::ToStdStr(id)); + TLMErrorLog::Info(string("Got parameter ID: ") + TLMErrorLog::ToStdStr(id)); // The index of the new interface: int idx = Parameters.size(); @@ -264,15 +264,15 @@ void PluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double time) { while(time > reqIfc->GetNextRecvTime()) { // while data is needed // Receive data untill there is info for this interface - string mess("Interface "); - TLMErrorLog::Log(mess + reqIfc->GetName() + - " needs data for time= " + TLMErrorLog::ToStdStr(time)); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info("Interface " + reqIfc->GetName() + + " needs data for time= " + TLMErrorLog::ToStdStr(time)); + } double allowedMaxTime = reqIfc->GetLastSendTime() + reqIfc->GetConnParams().Delay; if(allowedMaxTime < time && reqIfc->GetCausality() != "Input") { //Why not for signal interfaces? - string mess("WARNING: Interface "); - TLMErrorLog::Log(mess + reqIfc->GetName() + + TLMErrorLog::Warning("Interface " + reqIfc->GetName() + " is NOT ALLOWED to ask data after time= " + TLMErrorLog::ToStdStr(allowedMaxTime) + ". The error is: "+TLMErrorLog::ToStdStr(time - allowedMaxTime)); break; @@ -297,15 +297,19 @@ void PluginImplementer::ReceiveTimeData(TLMInterface* reqIfc, double time) { ifc->UnpackTimeData(Message); // Received data - TLMErrorLog::Log(string("Interface ") + ifc->GetName() + " got data until time= " - + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(string("Interface ") + ifc->GetName() + " got data until time= " + + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); + } } while(ifc != reqIfc); // loop until a message for this interface arrives if(ifc == NULL) break; // receive error - breaking - TLMErrorLog::Log(string("Got data until time=") + - TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(string("Got data until time=") + + TLMErrorLog::ToStdStr(ifc->GetNextRecvTime())); + } } } @@ -419,7 +423,7 @@ void PluginImplementer::SetMotion3D(int forceID, if(!ifc->waitForShutdown()) { // Store the data into the interface object - TLMErrorLog::Log(string("calling SetTimeData()")); + TLMErrorLog::Info(string("calling SetTimeData()")); ifc->SetTimeData(time, position, orientation,speed,ang_speed); } else { @@ -435,7 +439,7 @@ void PluginImplementer::SetMotion3D(int forceID, // needed anything ? #endif - TLMErrorLog::Log(string("Takedown due to finished interface data request.")); + TLMErrorLog::Info(string("Takedown due to finished interface data request.")); // If we got here, we have a shutdown request from all interfaces //abort(); // Some systems don't handle exit() very well, let's try abort(); @@ -459,7 +463,7 @@ void PluginImplementer::SetValueSignal(int valueID, if(!ifc->waitForShutdown()) { // Store the data into the interface object - TLMErrorLog::Log(string("calling SetTimeData()")); + TLMErrorLog::Info(string("calling SetTimeData()")); ifc->SetTimeData(time, value); } else { @@ -475,7 +479,7 @@ void PluginImplementer::SetValueSignal(int valueID, // needed anything ? #endif - TLMErrorLog::Log(string("Takedown due to finished interface data request.")); + TLMErrorLog::Info(string("Takedown due to finished interface data request.")); // If we got here, we have a shutdown request from all interfaces //abort(); // Some systems don't handle exit() very well, let's try abort(); @@ -498,7 +502,9 @@ void PluginImplementer::SetMotion1D(int forceID, if(!ifc->waitForShutdown()) { // Store the data into the interface object - TLMErrorLog::Log(string("calling SetTimeData()")); + if(TLMErrorLog::GetLogLevel() >= TLMLogLevel::Info) { + TLMErrorLog::Info(string("calling SetTimeData()")); + } ifc->SetTimeData(time, position, speed); } else { @@ -514,7 +520,7 @@ void PluginImplementer::SetMotion1D(int forceID, // needed anything ? #endif - TLMErrorLog::Log(string("Takedown due to finished interface data request.")); + TLMErrorLog::Info(string("Takedown due to finished interface data request.")); // If we got here, we have a shutdown request from all interfaces //abort(); // Some systems don't handle exit() very well, let's try abort(); diff --git a/common/Plugin/PluginImplementer.h b/common/Plugin/PluginImplementer.h index 666430c..b091f50 100644 --- a/common/Plugin/PluginImplementer.h +++ b/common/Plugin/PluginImplementer.h @@ -36,17 +36,6 @@ class PluginImplementer: public TLMPlugin { void SetInitialForce1D(int interfaceID, double force); void SetInitialValue(int interfaceID, double value); protected: - - //! SetDebugOut function enables/disables debug information - //! output from TLM plugin. - //! Input: if Enable is true - output is on, othewise - off. - virtual void SetDebugOut(bool Enable) { TLMErrorLog::SetDebugOut(Enable); } - - //! SetWarningOut function enables/disables warning information - //! output from TLM plugin. - //! Input: if Enable is true - output is on, othewise - off. - virtual void SetWarningOut(bool Enable) { TLMErrorLog::SetWarningOut(Enable); } - //! Connected flag tells if the connection to TLM manager is established. bool Connected; diff --git a/common/Plugin/TLMPlugin.h b/common/Plugin/TLMPlugin.h index 102dd2b..b2cdd07 100644 --- a/common/Plugin/TLMPlugin.h +++ b/common/Plugin/TLMPlugin.h @@ -37,16 +37,6 @@ class TLMPlugin { //! Destructor. Close TCP/IP connection and release memory. virtual ~TLMPlugin() {} - //! SetDebugOut function enables/disables debug information - //! output from TLM plugin. - //! Input: if Enable is true - output is on, othewise - off. - virtual void SetDebugOut(bool Enable) = 0; - - //! SetDebugOut function enables/disables warning information - //! output from TLM plugin. - //! Input: if Enable is true - output is on, othewise - off. - virtual void SetWarningOut(bool Enable) = 0; - //! Init method. Should be called after the default constructor. It will //! initialize the object and connect to TLMManager. Will return true //! on success, false otherwize. \note that the method can be called diff --git a/common/TLMTestApp.cc b/common/TLMTestApp.cc index c925f65..28bcd47 100644 --- a/common/TLMTestApp.cc +++ b/common/TLMTestApp.cc @@ -46,7 +46,6 @@ int main(int argn, char* argv[]) { ServerName = argv[7]; TLMPlugin* TlmForce = TLMPlugin::CreateInstance(); - TlmForce->SetDebugOut(true); if(!TlmForce->Init(Model, Time, TimeEnd, MaxStep, ServerName)) { cerr << "Failed to init TLM plugin" << endl;