From a9e425df1f00b6193961481da6146c3d4d6cbc8b Mon Sep 17 00:00:00 2001 From: Bertrand Coconnier Date: Sat, 19 Oct 2024 14:14:35 +0200 Subject: [PATCH] Convert the `flight_control` folder to the new logging system. --- src/models/atmosphere/FGMSIS.cpp | 15 ++-- src/models/flight_control/FGAccelerometer.cpp | 22 +++--- src/models/flight_control/FGActuator.cpp | 26 ++++--- src/models/flight_control/FGAngles.cpp | 10 +-- src/models/flight_control/FGDeadBand.cpp | 17 +++-- src/models/flight_control/FGDistributor.cpp | 27 +++---- src/models/flight_control/FGFCSComponent.cpp | 72 ++++++++++--------- src/models/flight_control/FGFCSFunction.cpp | 19 ++--- src/models/flight_control/FGFilter.cpp | 24 ++++--- src/models/flight_control/FGGain.cpp | 49 ++++++------- src/models/flight_control/FGGyro.cpp | 15 ++-- src/models/flight_control/FGKinemat.cpp | 28 ++++---- .../flight_control/FGLinearActuator.cpp | 65 +++++++++-------- src/models/flight_control/FGMagnetometer.cpp | 27 +++---- src/models/flight_control/FGPID.cpp | 13 ++-- src/models/flight_control/FGSensor.cpp | 62 ++++++++-------- .../flight_control/FGSensorOrientation.h | 12 ++-- src/models/flight_control/FGSummer.cpp | 18 ++--- src/models/flight_control/FGSwitch.cpp | 61 ++++++++++------ src/models/flight_control/FGSwitch.h | 7 +- src/models/flight_control/FGWaypoint.cpp | 71 +++++++++--------- 21 files changed, 364 insertions(+), 296 deletions(-) diff --git a/src/models/atmosphere/FGMSIS.cpp b/src/models/atmosphere/FGMSIS.cpp index dab5dd60c..5558c1a06 100644 --- a/src/models/atmosphere/FGMSIS.cpp +++ b/src/models/atmosphere/FGMSIS.cpp @@ -60,6 +60,7 @@ INCLUDES #include "FGFDMExec.h" #include "FGMSIS.h" +#include "input_output/FGLog.h" using namespace std; @@ -212,7 +213,7 @@ void FGMSIS::Compute(double altitude, double& pressure, double& temperature, // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -230,14 +231,16 @@ void FGMSIS::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) {} // Constructor if (from == 3) { // Loading - cout << " NRLMSIS atmosphere model" << endl; - cout << " day: " << day_of_year << endl; - cout << " UTC: " << seconds_in_day << endl << endl; + FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG); + log << " NRLMSIS atmosphere model\n" << fixed; + log << " day: " << day_of_year << "\n"; + log << " UTC: " << seconds_in_day << "\n\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) std::cout << "Instantiated: MSIS" << std::endl; - if (from == 1) std::cout << "Destroyed: MSIS" << std::endl; + FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: MSIS\n"; + if (from == 1) log << "Destroyed: MSIS\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGAccelerometer.cpp b/src/models/flight_control/FGAccelerometer.cpp index 6d7962815..95b4122b0 100644 --- a/src/models/flight_control/FGAccelerometer.cpp +++ b/src/models/flight_control/FGAccelerometer.cpp @@ -52,19 +52,19 @@ CLASS IMPLEMENTATION FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) : FGSensor(fcs, element), - FGSensorOrientation(element) + FGSensorOrientation(element, fcs->GetExec()->GetLogger()) { Propagate = fcs->GetExec()->GetPropagate(); Accelerations = fcs->GetExec()->GetAccelerations(); MassBalance = fcs->GetExec()->GetMassBalance(); - + Element* location_element = element->FindElement("location"); if (location_element) vLocation = location_element->FindElementTripletConvertTo("IN"); else { - cerr << element->ReadFrom() - << "No location given for accelerometer. " << endl; - throw("Malformed accelerometer specification"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "No location given for accelerometer.\n"; + throw BaseException(log.str()); } vRadius = MassBalance->StructuralToBody(vLocation); @@ -86,7 +86,7 @@ bool FGAccelerometer::Run(void ) // There is no input assumed. This is a dedicated acceleration sensor. vRadius = MassBalance->StructuralToBody(vLocation); - + //aircraft forces vAccel = (Accelerations->GetBodyAccel() + Accelerations->GetPQRidot() * vRadius @@ -112,7 +112,7 @@ bool FGAccelerometer::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -131,12 +131,14 @@ void FGAccelerometer::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " Axis: " << ax[axis] << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " Axis: " << ax[axis] << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGAccelerometer" << endl; - if (from == 1) cout << "Destroyed: FGAccelerometer" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGAccelerometer\n"; + if (from == 1) log << "Destroyed: FGAccelerometer\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGActuator.cpp b/src/models/flight_control/FGActuator.cpp index e2d40666e..44b213e5e 100644 --- a/src/models/flight_control/FGActuator.cpp +++ b/src/models/flight_control/FGActuator.cpp @@ -41,6 +41,7 @@ INCLUDES #include "input_output/FGXMLElement.h" #include "math/FGParameterValue.h" #include "models/FGFCS.h" +#include "input_output/FGLog.h" using namespace std; @@ -319,7 +320,7 @@ void FGActuator::InitializeLagCoefficients() // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -336,27 +337,30 @@ void FGActuator::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetNameWithSign() << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " INPUT: " << InputNodes[0]->GetNameWithSign() << fixed + << setprecision(4) << "\n"; if (!OutputNodes.empty()) { for (auto node: OutputNodes) - cout << " OUTPUT: " << node->GetName() << endl; + log << " OUTPUT: " << node->GetName() << "\n"; } - if (bias != 0.0) cout << " Bias: " << bias << endl; + if (bias != 0.0) log << " Bias: " << bias << "\n"; if (rate_limit_incr != 0) { - cout << " Increasing rate limit: " << rate_limit_incr->GetName() << endl; + log << " Increasing rate limit: " << rate_limit_incr->GetName() << "\n"; } if (rate_limit_decr != 0) { - cout << " Decreasing rate limit: " << rate_limit_decr->GetName() << endl; + log << " Decreasing rate limit: " << rate_limit_decr->GetName() << "\n"; } - if (lag != 0) cout << " Actuator lag: " << lag->GetName() << endl; - if (hysteresis_width != 0) cout << " Hysteresis width: " << hysteresis_width << endl; - if (deadband_width != 0) cout << " Deadband width: " << deadband_width << endl; + if (lag != 0) log << " Actuator lag: " << lag->GetName() << "\n"; + if (hysteresis_width != 0) log << " Hysteresis width: " << hysteresis_width << "\n"; + if (deadband_width != 0) log << " Deadband width: " << deadband_width << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGActuator" << endl; - if (from == 1) cout << "Destroyed: FGActuator" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGActuator\n"; + if (from == 1) log << "Destroyed: FGActuator\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGAngles.cpp b/src/models/flight_control/FGAngles.cpp index 0b53ccef8..40818e477 100644 --- a/src/models/flight_control/FGAngles.cpp +++ b/src/models/flight_control/FGAngles.cpp @@ -39,7 +39,7 @@ COMMENTS, REFERENCES, and NOTES from the current heading. The sense of the rotation to get to that angle is also calculated (positive 1 for a clockwise rotation, negative 1 for counter- clockwise). - + The angle to the heading is calculated as follows: Given an angle phi: @@ -70,6 +70,7 @@ INCLUDES #include "FGAngles.h" #include "models/FGFCS.h" #include "input_output/FGXMLElement.h" +#include "input_output/FGLog.h" using namespace std; @@ -167,7 +168,7 @@ bool FGAngles::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -187,8 +188,9 @@ void FGAngles::Debug(int from) } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGAngles" << endl; - if (from == 1) cout << "Destroyed: FGAngles" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGAngles\n"; + if (from == 1) log << "Destroyed: FGAngles\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGDeadBand.cpp b/src/models/flight_control/FGDeadBand.cpp index a9c7dc6b2..6b6eeec8e 100644 --- a/src/models/flight_control/FGDeadBand.cpp +++ b/src/models/flight_control/FGDeadBand.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGDeadBand.h" #include "models/FGFCS.h" #include "math/FGParameterValue.h" +#include "input_output/FGLog.h" using namespace std; @@ -110,7 +111,7 @@ bool FGDeadBand::Run(void) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -127,17 +128,19 @@ void FGDeadBand::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetName() << endl; - cout << " DEADBAND WIDTH: " << Width->GetName() << endl; - cout << " GAIN: " << gain << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " INPUT: " << InputNodes[0]->GetName() << "\n"; + log << " DEADBAND WIDTH: " << Width->GetName() << "\n"; + log << " GAIN: " << fixed << setprecision(4) << gain << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGDeadBand" << endl; - if (from == 1) cout << "Destroyed: FGDeadBand" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGDeadBand\n"; + if (from == 1) log << "Destroyed: FGDeadBand\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGDistributor.cpp b/src/models/flight_control/FGDistributor.cpp index 38a301449..288d16610 100644 --- a/src/models/flight_control/FGDistributor.cpp +++ b/src/models/flight_control/FGDistributor.cpp @@ -38,9 +38,10 @@ Also, see the header file (FGDistributor.h) for further details. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - + #include "FGDistributor.h" #include "models/FGFCS.h" +#include "input_output/FGLog.h" using namespace std; @@ -120,7 +121,7 @@ bool FGDistributor::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -137,29 +138,31 @@ void FGDistributor::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); unsigned int ctr=0; for (auto Case: Cases) { - std::cout << " Case: " << ctr << endl; + log << " Case: " << fixed << ctr << "\n"; if (Case->HasTest()) { Case->GetTest()->PrintCondition(" "); } else { - std::cout << " Set these properties by default: " << std::endl; + log << " Set these properties by default: \n"; } - std::cout << std::endl; + log << "\n"; for (auto propVal = Case->IterPropValPairs(); propVal != Case->EndPropValPairs(); ++propVal) { - std::cout << " Set property " << (*propVal)->GetPropName(); - if ((*propVal)->GetLateBoundProp()) std::cout << " (late bound)"; - std::cout << " to " << (*propVal)->GetValString(); - if ((*propVal)->GetLateBoundValue()) std::cout << " (late bound)"; - std::cout << std::endl; + log << " Set property " << (*propVal)->GetPropName(); + if ((*propVal)->GetLateBoundProp()) log << " (late bound)"; + log << " to " << (*propVal)->GetValString(); + if ((*propVal)->GetLateBoundValue()) log << " (late bound)"; + log << "\n"; } ctr++; } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGDistributor" << endl; - if (from == 1) cout << "Destroyed: FGDistributor" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGDistributor\n"; + if (from == 1) log << "Destroyed: FGDistributor\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGFCSComponent.cpp b/src/models/flight_control/FGFCSComponent.cpp index 6542f2c0d..1f2e6deb3 100644 --- a/src/models/flight_control/FGFCSComponent.cpp +++ b/src/models/flight_control/FGFCSComponent.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGFCSComponent.h" #include "models/FGFCS.h" #include "math/FGParameterValue.h" +#include "input_output/FGLog.h" using namespace std; @@ -131,9 +132,9 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) bool node_exists = PropertyManager->HasNode(output_node_name); FGPropertyNode* OutputNode = PropertyManager->GetNode( output_node_name, true ); if (!OutputNode) { - cerr << out_elem->ReadFrom() << " Unable to process property: " - << output_node_name << endl; - throw(string("Invalid output property name in flight control definition")); + FGXMLLogging log(fcs->GetExec()->GetLogger(), out_elem, LogLevel::FATAL); + log << " Unable to process property: " << output_node_name << "\n"; + throw BaseException(log.str()); } OutputNodes.push_back(OutputNode); // If the node has just been created then it must be initialized to a @@ -157,7 +158,8 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) } else if (delayType == "frames") { delay = (unsigned int)delay_time; } else { - cerr << "Unallowed delay type" << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), delay_elem, LogLevel::ERROR); + log << "Unallowed delay type\n"; } } else { delay = (unsigned int)(delay_time / dt); @@ -170,8 +172,8 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) if (clip_el) { Element* el = clip_el->FindElement("min"); if (!el) { - cerr << clip_el->ReadFrom() - << "Element is missing, is ignored." << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), clip_el, LogLevel::ERROR); + log << "Element is missing, is ignored.\n"; return; } @@ -179,8 +181,8 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) el = clip_el->FindElement("max"); if (!el) { - cerr << clip_el->ReadFrom() - << "Element is missing, is ignored." << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), clip_el, LogLevel::ERROR); + log << "Element is missing, is ignored.\n"; ClipMin = nullptr; return; } @@ -219,20 +221,19 @@ void FGFCSComponent::CheckInputNodes(size_t MinNodes, size_t MaxNodes, Element* size_t num = InputNodes.size(); if (num < MinNodes) { - cerr << el->ReadFrom() - << " Not enough nodes are provided" << endl - << " Expecting " << MinNodes << " while " << num - << " are provided." << endl; - throw("Some inputs are missing."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), el, LogLevel::FATAL); + log << " Not enough nodes are provided\n" + << " Expecting " << MinNodes << " while " << num + << " are provided.\n"; + throw BaseException(log.str()); } if (num > MaxNodes) { - cerr << el->ReadFrom() - << " Too many nodes are provided" << endl - << " Expecting " << MaxNodes << " while " << num - << " are provided." << endl - << " The last " << num-MaxNodes << " input nodes will be ignored." - << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), el, LogLevel::ERROR); + log << " Too many nodes are provided\n" + << " Expecting " << MaxNodes << " while " << num + << " are provided.\n" + << " The last " << num-MaxNodes << " input nodes will be ignored.\n"; } } @@ -271,10 +272,11 @@ void FGFCSComponent::Clip(void) double range = vmax - vmin; if (range < 0.0) { - cerr << "Trying to clip with a max value (" << vmax << ") from " - << ClipMax->GetName() << " lower than the min value (" << vmin - << ") from " << ClipMin->GetName() << "." << endl - << "Clipping is ignored." << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::ERROR); + log << "Trying to clip with a max value (" << fixed << vmax << ") from " + << ClipMax->GetName() << " lower than the min value (" << vmin + << ") from " << ClipMin->GetName() << ".\n" + << "Clipping is ignored.\n"; return; } @@ -319,8 +321,8 @@ void FGFCSComponent::bind(Element* el, FGPropertyManager* PropertyManager) node->setDoubleValue(Output); } else { - cerr << el->ReadFrom() - << "Could not get or create property " << tmp << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), el, LogLevel::ERROR); + log << "Could not get or create property " << tmp << "\n"; } } @@ -332,7 +334,7 @@ void FGFCSComponent::bind(Element* el, FGPropertyManager* PropertyManager) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -349,20 +351,22 @@ void FGFCSComponent::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { - cout << endl << " Loading Component \"" << Name - << "\" of type: " << Type << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << "\n Loading Component \"" << Name << fixed + << "\" of type: " << Type << "\n"; if (clip) { - cout << " Minimum limit: " << ClipMin->GetName() << endl; - cout << " Maximum limit: " << ClipMax->GetName() << endl; + log << " Minimum limit: " << ClipMin->GetName() << "\n"; + log << " Maximum limit: " << ClipMax->GetName() << "\n"; } - if (delay > 0) cout <<" Frame delay: " << delay - << " frames (" << delay*dt << " sec)" << endl; + if (delay > 0) log <<" Frame delay: " << delay << fixed + << setprecision(4) << " frames (" << delay*dt << " sec)\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGFCSComponent" << endl; - if (from == 1) cout << "Destroyed: FGFCSComponent" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGFCSComponent\n"; + if (from == 1) log << "Destroyed: FGFCSComponent\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGFCSFunction.cpp b/src/models/flight_control/FGFCSFunction.cpp index 64d516e88..67e3f254d 100644 --- a/src/models/flight_control/FGFCSFunction.cpp +++ b/src/models/flight_control/FGFCSFunction.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGFCSFunction.h" #include "models/FGFCS.h" #include "input_output/FGXMLElement.h" +#include "input_output/FGLog.h" using namespace std; @@ -59,9 +60,9 @@ FGFCSFunction::FGFCSFunction(FGFCS* fcs, Element* element) if (function_element) function = new FGFunction(fcs->GetExec(), function_element); else { - cerr << element->ReadFrom() - << "FCS Function should contain a \"function\" element" << endl; - throw("Malformed FCS function specification."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "FCS Function should contain a \"function\" element\n"; + throw BaseException(log.str()); } bind(element, fcs->GetPropertyManager().get()); @@ -101,7 +102,7 @@ bool FGFCSFunction::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -118,15 +119,17 @@ void FGFCSFunction::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (!InputNodes.empty()) - cout << " INPUT: " << InputNodes[0]->GetName() << endl; + log << " INPUT: " << InputNodes[0]->GetName() << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGFCSFunction" << endl; - if (from == 1) cout << "Destroyed: FGFCSFunction" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGFCSFunction\n"; + if (from == 1) log << "Destroyed: FGFCSFunction\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGFilter.cpp b/src/models/flight_control/FGFilter.cpp index a1a5fd6a6..ff49e28f2 100644 --- a/src/models/flight_control/FGFilter.cpp +++ b/src/models/flight_control/FGFilter.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGFilter.h" #include "models/FGFCS.h" #include "math/FGParameterValue.h" +#include "input_output/FGLog.h" using namespace std; @@ -139,7 +140,10 @@ void FGFilter::CalculateDynamicFilters(void) cb = (2.0 - dt*C[1]) / denom; break; case eUnknown: - cerr << "Unknown filter type" << endl; + { + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::ERROR); + log << "Unknown filter type\n"; + } break; } @@ -199,7 +203,7 @@ bool FGFilter::Run(void) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -216,23 +220,25 @@ void FGFilter::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetName() << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " INPUT: " << InputNodes[0]->GetName() << fixed << "\n"; for (int i=1; i < 7; i++) { if (!C[i]) break; - cout << " C[" << i << "]"; - if (!C[i]->IsConstant()) cout << " is the value of property"; - cout << ": "<< C[i]->GetName() << endl; + log << " C[" << i << "]"; + if (!C[i]->IsConstant()) log << " is the value of property"; + log << ": "<< C[i]->GetName() << "\n"; } for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGFilter" << endl; - if (from == 1) cout << "Destroyed: FGFilter" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGFilter\n"; + if (from == 1) log << "Destroyed: FGFilter\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGGain.cpp b/src/models/flight_control/FGGain.cpp index cb8eb117a..c12b18367 100644 --- a/src/models/flight_control/FGGain.cpp +++ b/src/models/flight_control/FGGain.cpp @@ -41,6 +41,7 @@ INCLUDES #include "models/FGFCS.h" #include "math/FGParameterValue.h" #include "math/FGTable.h" +#include "input_output/FGLog.h" using namespace std; @@ -62,9 +63,8 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) if (Type == "PURE_GAIN") { if ( !element->FindElement("gain") ) { - cerr << element->ReadFrom() - << highint << " No GAIN specified (default: 1.0)" << normint - << endl; + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::ERROR); + log << LogFormat::BOLD << " No GAIN specified (default: 1.0)\n"; } } @@ -92,10 +92,10 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) OutMax = scale_element->FindElementValueAsNumber("max"); OutMin = scale_element->FindElementValueAsNumber("min"); } else { - cerr << scale_element->ReadFrom() - << "Maximum and minimum output values must be supplied for the " - "aerosurface scale component" << endl; - throw("Some inputs are missing."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), scale_element, LogLevel::FATAL); + log << "Maximum and minimum output values must be supplied for the " + "aerosurface scale component\n"; + throw BaseException(log.str()); } ZeroCentered = true; Element* zero_centered = element->FindElement("zero_centered"); @@ -112,10 +112,9 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) if (element->FindElement("table")) { Table = new FGTable(PropertyManager, element->FindElement("table")); } else { - cerr << element->ReadFrom() - << "A table must be provided for the scheduled gain component" - << endl; - throw("Some inputs are missing."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "A table must be provided for the scheduled gain component\n"; + throw BaseException(log.str()); } } @@ -179,7 +178,7 @@ bool FGGain::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -196,28 +195,30 @@ void FGGain::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetNameWithSign() << endl; - cout << " GAIN: " << Gain->GetName() << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " INPUT: " << InputNodes[0]->GetNameWithSign() << "\n"; + log << " GAIN: " << Gain->GetName() << fixed << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; if (Type == "AEROSURFACE_SCALE") { - cout << " In/Out Mapping:" << endl; - cout << " Input MIN: " << InMin << endl; - cout << " Input MAX: " << InMax << endl; - cout << " Output MIN: " << OutMin << endl; - cout << " Output MAX: " << OutMax << endl; + log << " In/Out Mapping:\n" << setprecision(4); + log << " Input MIN: " << InMin << "\n"; + log << " Input MAX: " << InMax << "\n"; + log << " Output MIN: " << OutMin << "\n"; + log << " Output MAX: " << OutMax << "\n"; } - if (Table != 0) { - cout << " Scheduled by table: " << endl; + if (Table) { + log << " Scheduled by table:\n"; Table->Print(); } } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGGain" << endl; - if (from == 1) cout << "Destroyed: FGGain" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGGain\n"; + if (from == 1) log << "Destroyed: FGGain\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGGyro.cpp b/src/models/flight_control/FGGyro.cpp index f144422b5..81cb6e347 100644 --- a/src/models/flight_control/FGGyro.cpp +++ b/src/models/flight_control/FGGyro.cpp @@ -48,8 +48,9 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGGyro::FGGyro(FGFCS* fcs, Element* element) : FGSensor(fcs, element), - FGSensorOrientation(element) +FGGyro::FGGyro(FGFCS* fcs, Element* element) + : FGSensor(fcs, element), + FGSensorOrientation(element, fcs->GetExec()->GetLogger()) { Propagate = fcs->GetExec()->GetPropagate(); @@ -92,7 +93,7 @@ bool FGGyro::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -110,13 +111,15 @@ void FGGyro::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor - cout << " Axis: " << ax[axis] << endl; + log << " Axis: " << ax[axis] << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGGyro" << endl; - if (from == 1) cout << "Destroyed: FGGyro" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGGyro\n"; + if (from == 1) log << "Destroyed: FGGyro\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGKinemat.cpp b/src/models/flight_control/FGKinemat.cpp index 2140cfda1..579f80725 100644 --- a/src/models/flight_control/FGKinemat.cpp +++ b/src/models/flight_control/FGKinemat.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGKinemat.h" #include "input_output/FGXMLElement.h" #include "models/FGFCS.h" +#include "input_output/FGLog.h" using namespace std; @@ -70,11 +71,10 @@ FGKinemat::FGKinemat(FGFCS* fcs, Element* element) } if (Detents.size() <= 1) { - stringstream s; - s << "Kinematic component " << Name - << " must have more than 1 setting element"; - cerr << element->ReadFrom() << endl << s.str() << endl; - throw BaseException(s.str()); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "\nKinematic component " << Name + << " must have more than 1 setting element\n"; + throw BaseException(log.str()); } bind(element, fcs->GetPropertyManager().get()); @@ -162,7 +162,7 @@ bool FGKinemat::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -178,20 +178,22 @@ void FGKinemat::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetName() << endl; - cout << " DETENTS: " << Detents.size() << endl; + log << " INPUT: " << InputNodes[0]->GetName() << "\n"; + log << " DETENTS: " << Detents.size() << fixed << setprecision(4) << "\n"; for (unsigned int i=0;igetNameString() << endl; - if (!DoScale) cout << " NOSCALE" << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; + if (!DoScale) log << " NOSCALE\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGKinemat" << endl; - if (from == 1) cout << "Destroyed: FGKinemat" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGKinemat\n"; + if (from == 1) log << "Destroyed: FGKinemat\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGLinearActuator.cpp b/src/models/flight_control/FGLinearActuator.cpp index e0fb4c0d4..6ce91bae5 100644 --- a/src/models/flight_control/FGLinearActuator.cpp +++ b/src/models/flight_control/FGLinearActuator.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGLinearActuator.h" #include "models/FGFCS.h" #include "math/FGParameterValue.h" +#include "input_output/FGLog.h" using namespace std; @@ -94,9 +95,10 @@ FGLinearActuator::FGLinearActuator(FGFCS* fcs, Element* element) if (element->FindElement("module")) { module = element->FindElementValueAsNumber("module"); if (module < 0) { - cout << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() - << " parameter is forced from " << module - << " value to 1.0 value" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::WARN); + log << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() + << " parameter is forced from " << fixed << module + << " value to 1.0 value\n"; module = 1.0; } } @@ -104,9 +106,10 @@ FGLinearActuator::FGLinearActuator(FGFCS* fcs, Element* element) if (element->FindElement("hysteresis")) { hysteresis = element->FindElementValueAsNumber("hysteresis"); if (hysteresis < 0) { - cout << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() - << " parameter is forced from " << hysteresis - << " value to 0.0 value" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::WARN); + log << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() + << " parameter is forced from " << fixed << hysteresis + << " value to 0.0 value\n"; hysteresis = 0.0; } } @@ -120,9 +123,10 @@ FGLinearActuator::FGLinearActuator(FGFCS* fcs, Element* element) previousLagInput = previousLagOutput = 0.0; } else { if (lag < 0) { - cout << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() - << " parameter is forced from " - << lag << " value to 0.0 value" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::WARN); + log << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() + << " parameter is forced from " << fixed << lag + << " value to 0.0 value\n"; lag = 0; } } @@ -131,9 +135,10 @@ FGLinearActuator::FGLinearActuator(FGFCS* fcs, Element* element) if (element->FindElement("rate")) { rate = element->FindElementValueAsNumber("rate"); if (rate <= 0 || rate > 1.0) { - cout << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() - << " parameter is forced from " << rate - << " value to 0.5 value" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::WARN); + log << "FGLinearActuator::Run " << InputNodes[0]->GetNameWithSign() + << " parameter is forced from " << fixed << rate + << " value to 0.5 value\n"; rate = 0.5; } } @@ -225,7 +230,7 @@ bool FGLinearActuator::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -241,26 +246,28 @@ void FGLinearActuator::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetNameWithSign() << endl; - cout << " inputMem: " << inputMem << endl; - cout << " bias: " << bias << endl; - cout << " module: " << module << endl; - cout << " hysteresis: " << hysteresis << endl; - cout << " rate: " << rate << endl; - cout << " versus: " << versus << endl; - cout << " direction: " << direction << endl; - cout << " countSpin: " << countSpin << endl; - cout << " Lag: " << lag << endl; - cout << " Gain: " << gain << endl; - cout << " set: " << set << endl; - cout << " reset: " << reset << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + log << " INPUT: " << InputNodes[0]->GetNameWithSign() << fixed << "\n"; + log << " inputMem: " << inputMem << "\n"; + log << " bias: " << bias << "\n"; + log << " module: " << module << "\n"; + log << " hysteresis: " << hysteresis << "\n"; + log << " rate: " << rate << "\n"; + log << " versus: " << versus << "\n"; + log << " direction: " << direction << "\n"; + log << " countSpin: " << countSpin << "\n"; + log << " Lag: " << lag << "\n"; + log << " Gain: " << gain << "\n"; + log << " set: " << set << "\n"; + log << " reset: " << reset << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->GetName() << endl; + log << " OUTPUT: " << node->GetName() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGLinearActuator" << endl; - if (from == 1) cout << "Destroyed: FGLinearActuator" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGLinearActuator\n"; + if (from == 1) log << "Destroyed: FGLinearActuator\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGMagnetometer.cpp b/src/models/flight_control/FGMagnetometer.cpp index 14218bde0..61f7a5d89 100644 --- a/src/models/flight_control/FGMagnetometer.cpp +++ b/src/models/flight_control/FGMagnetometer.cpp @@ -52,20 +52,21 @@ CLASS IMPLEMENTATION FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element) - : FGSensor(fcs, element), FGSensorOrientation(element), counter(0), - INERTIAL_UPDATE_RATE(1000) + : FGSensor(fcs, element), + FGSensorOrientation(element, fcs->GetExec()->GetLogger()), + counter(0), INERTIAL_UPDATE_RATE(1000) { Propagate = fcs->GetExec()->GetPropagate(); MassBalance = fcs->GetExec()->GetMassBalance(); Inertial = fcs->GetExec()->GetInertial(); - + Element* location_element = element->FindElement("location"); if (location_element) vLocation = location_element->FindElementTripletConvertTo("IN"); else { - cerr << element->ReadFrom() - << "No location given for magnetometer. " << endl; - throw("Malformed magnetometer specification."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "No location given for magnetometer.\n"; + throw BaseException(log.str()); } vRadius = MassBalance->StructuralToBody(vLocation); @@ -127,7 +128,7 @@ void FGMagnetometer::updateInertialMag(void) bool FGMagnetometer::Run(void ) { // There is no input assumed. This is a dedicated magnetic field sensor. - + vRadius = MassBalance->StructuralToBody(vLocation); updateInertialMag(); @@ -137,7 +138,7 @@ bool FGMagnetometer::Run(void ) // Allow for sensor orientation vMag = mT * vMag; - + Input = vMag(axis); ProcessSensorSignal(); @@ -155,7 +156,7 @@ bool FGMagnetometer::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -173,13 +174,15 @@ void FGMagnetometer::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor - cout << " Axis: " << ax[axis] << endl; + log << " Axis: " << ax[axis] << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGMagnetometer" << endl; - if (from == 1) cout << "Destroyed: FGMagnetometer" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGMagnetometer\n"; + if (from == 1) log << "Destroyed: FGMagnetometer\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGPID.cpp b/src/models/flight_control/FGPID.cpp index 330b2a95c..276b279cb 100644 --- a/src/models/flight_control/FGPID.cpp +++ b/src/models/flight_control/FGPID.cpp @@ -38,6 +38,7 @@ INCLUDES #include "FGPID.h" #include "models/FGFCS.h" #include "math/FGParameterValue.h" +#include "input_output/FGLog.h" using namespace std; @@ -219,7 +220,7 @@ bool FGPID::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -235,16 +236,18 @@ void FGPID::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor - cout << " INPUT: " << InputNodes[0]->GetNameWithSign() << endl; + log << " INPUT: " << InputNodes[0]->GetNameWithSign() << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGPID" << endl; - if (from == 1) cout << "Destroyed: FGPID" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGPID\n"; + if (from == 1) log << "Destroyed: FGPID\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGSensor.cpp b/src/models/flight_control/FGSensor.cpp index 820eb33dd..8905a7578 100644 --- a/src/models/flight_control/FGSensor.cpp +++ b/src/models/flight_control/FGSensor.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGSensor.h" #include "models/FGFCS.h" #include "input_output/FGXMLElement.h" +#include "input_output/FGLog.h" using namespace std; @@ -102,8 +103,9 @@ FGSensor::FGSensor(FGFCS* fcs, Element* element) NoiseType = eAbsolute; } else { NoiseType = ePercent; - cerr << "Unknown noise type in sensor: " << Name << endl; - cerr << " defaulting to PERCENT." << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::ERROR); + log << "Unknown noise type in sensor: " << Name + << "\n defaulting to PERCENT.\n"; } string distribution = element->FindElement("noise")->GetAttributeValue("distribution"); if (distribution == "UNIFORM") { @@ -112,8 +114,9 @@ FGSensor::FGSensor(FGFCS* fcs, Element* element) DistributionType = eGaussian; } else { DistributionType = eUniform; - cerr << "Unknown random distribution type in sensor: " << Name << endl; - cerr << " defaulting to UNIFORM." << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::ERROR); + log << "Unknown random distribution type in sensor: " << Name + << "\n defaulting to UNIFORM.\n"; } } @@ -261,15 +264,15 @@ void FGSensor::bind(Element* el, FGPropertyManager* PropertyManager) PropertyManager->Tie( tmp_low, this, &FGSensor::GetFailLow, &FGSensor::SetFailLow); PropertyManager->Tie( tmp_high, this, &FGSensor::GetFailHigh, &FGSensor::SetFailHigh); PropertyManager->Tie( tmp_stuck, this, &FGSensor::GetFailStuck, &FGSensor::SetFailStuck); - + if (!quant_property.empty()) { if (quant_property.find("/") == string::npos) { // not found string qprop = "fcs/" + PropertyManager->mkPropertyName(quant_property, true); FGPropertyNode* node = PropertyManager->GetNode(qprop, true); if (node->isTied()) { - cerr << el->ReadFrom() - << "Property " << tmp << " has already been successfully bound (late)." << endl; - throw("Failed to bind the property to an existing already tied node."); + FGXMLLogging log(fcs->GetExec()->GetLogger(), el, LogLevel::FATAL); + log << "Property " << tmp << " has already been successfully bound (late).\n"; + throw BaseException(log.str()); } else PropertyManager->Tie(qprop, this, &FGSensor::GetQuantized); @@ -286,7 +289,7 @@ void FGSensor::bind(Element* el, FGPropertyManager* PropertyManager) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -302,45 +305,48 @@ void FGSensor::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor if (!InputNodes.empty()) - cout << " INPUT: " << InputNodes[0]->GetNameWithSign() << endl; + log << " INPUT: " << InputNodes[0]->GetNameWithSign() << fixed + << setprecision(4) << "\n"; if (bits != 0) { if (quant_property.empty()) - cout << " Quantized output" << endl; + log << " Quantized output\n"; else - cout << " Quantized output (property: " << quant_property << ")" << endl; + log << " Quantized output (property: " << quant_property << ")\n"; - cout << " Bits: " << bits << endl; - cout << " Min value: " << min << endl; - cout << " Max value: " << max << endl; - cout << " (span: " << span << ", granularity: " << granularity << ")" << endl; + log << " Bits: " << bits << "\n"; + log << " Min value: " << min << "\n"; + log << " Max value: " << max << "\n"; + log << " (span: " << span << ", granularity: " << granularity << ")\n"; } - if (bias != 0.0) cout << " Bias: " << bias << endl; - if (gain != 0.0) cout << " Gain: " << gain << endl; - if (drift_rate != 0) cout << " Sensor drift rate: " << drift_rate << endl; - if (lag != 0) cout << " Sensor lag: " << lag << endl; + if (bias != 0.0) log << " Bias: " << bias << " \n"; + if (gain != 0.0) log << " Gain: " << gain << " \n"; + if (drift_rate != 0) log << " Sensor drift rate: " << drift_rate << " \n"; + if (lag != 0) log << " Sensor lag: " << lag << " \n"; if (noise_variance != 0) { if (NoiseType == eAbsolute) { - cout << " Noise variance (absolute): " << noise_variance << endl; + log << " Noise variance (absolute): " << noise_variance << " \n"; } else if (NoiseType == ePercent) { - cout << " Noise variance (percent): " << noise_variance << endl; + log << " Noise variance (percent): " << noise_variance << " \n"; } else { - cout << " Noise variance type is invalid" << endl; + log << " Noise variance type is invalid\n"; } if (DistributionType == eUniform) { - cout << " Random noise is uniformly distributed." << endl; + log << " Random noise is uniformly distributed.\n"; } else if (DistributionType == eGaussian) { - cout << " Random noise is gaussian distributed." << endl; + log << " Random noise is gaussian distributed.\n"; } } for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGSensor" << endl; - if (from == 1) cout << "Destroyed: FGSensor" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGSensor\n"; + if (from == 1) log << "Destroyed: FGSensor\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } diff --git a/src/models/flight_control/FGSensorOrientation.h b/src/models/flight_control/FGSensorOrientation.h index 0c62034d0..21f387743 100644 --- a/src/models/flight_control/FGSensorOrientation.h +++ b/src/models/flight_control/FGSensorOrientation.h @@ -41,6 +41,7 @@ INCLUDES #include "input_output/FGXMLElement.h" #include "math/FGColumnVector3.h" #include "math/FGMatrix33.h" +#include "input_output/FGLog.h" #include @@ -69,7 +70,7 @@ CLASS DECLARATION class FGSensorOrientation : public FGJSBBase { public: - FGSensorOrientation(Element* element) + FGSensorOrientation(Element* element, std::shared_ptr logger) { Element* orient_element = element->FindElement("orientation"); if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); @@ -78,7 +79,7 @@ class FGSensorOrientation : public FGJSBBase Element* axis_element = element->FindElement("axis"); if (axis_element) { - std::string sAxis = element->FindElementValue("axis"); + std::string sAxis = axis_element->GetDataLine(); if (sAxis == "X" || sAxis == "x") { axis = 1; } else if (sAxis == "Y" || sAxis == "y") { @@ -88,16 +89,15 @@ class FGSensorOrientation : public FGJSBBase } } - if (!axis) { - std::cerr << " Incorrect/no axis specified for this sensor; assuming X axis" << std::endl; + if (axis == 0) { + FGXMLLogging log(logger, element, LogLevel::WARN); + log << " Incorrect/no axis specified for this sensor; assuming X axis\n"; axis = 1; } CalculateTransformMatrix(); } -// ~FGSensorOrientation(); - protected: FGColumnVector3 vOrient; FGMatrix33 mT; diff --git a/src/models/flight_control/FGSummer.cpp b/src/models/flight_control/FGSummer.cpp index 4e43666a8..9c81b4905 100644 --- a/src/models/flight_control/FGSummer.cpp +++ b/src/models/flight_control/FGSummer.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGSummer.h" #include "models/FGFCS.h" #include "input_output/FGXMLElement.h" +#include "input_output/FGLog.h" using namespace std; @@ -92,7 +93,7 @@ bool FGSummer::Run(void) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -108,18 +109,20 @@ void FGSummer::Debug(int from) if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); if (from == 0) { // Constructor - cout << " INPUTS: " << endl; + log << " INPUTS: " << fixed << "\n"; for (auto node: InputNodes) - cout << " " << node->GetNameWithSign() << endl; - if (Bias != 0.0) cout << " Bias: " << Bias << endl; + log << " " << node->GetNameWithSign() << "\n"; + if (Bias != 0.0) log << " Bias: " << Bias << "\n"; for (auto node: OutputNodes) - cout << " OUTPUT: " << node->GetName() << endl; + log << " OUTPUT: " << node->GetName() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGSummer" << endl; - if (from == 1) cout << "Destroyed: FGSummer" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGSummer\n"; + if (from == 1) log << "Destroyed: FGSummer\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } @@ -134,4 +137,3 @@ void FGSummer::Debug(int from) } } //namespace JSBSim - diff --git a/src/models/flight_control/FGSwitch.cpp b/src/models/flight_control/FGSwitch.cpp index a1e9f731c..380265a8b 100644 --- a/src/models/flight_control/FGSwitch.cpp +++ b/src/models/flight_control/FGSwitch.cpp @@ -64,6 +64,7 @@ INCLUDES #include "FGSwitch.h" #include "models/FGFCS.h" #include "math/FGCondition.h" +#include "input_output/FGLog.h" using namespace std; @@ -83,26 +84,39 @@ FGSwitch::FGSwitch(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) // definition for a sample-and-hold Element* test_element = element->FindElement("default"); if (test_element) { - current_test = new Test; - value = test_element->GetAttributeValue("value"); - current_test->setTestValue(value, Name, PropertyManager, test_element); - current_test->Default = true; - if (delay > 0 && is_number(trim(value))) { // If there is a delay, initialize the - double v = atof_locale_c(value); - for (unsigned int i=0; iGetAttributeValue("value"); + current_test->setTestValue(value, Name, PropertyManager, test_element); + current_test->Default = true; + if (delay > 0 && is_number(trim(value))) { // If there is a delay, initialize the + double v = atof_locale_c(value); + for (unsigned int i=0; iGetExec()->GetLogger(), test_element, LogLevel::ERROR); + log << e.what() << "\n" + << " Default value IGNORED.\n"; } - tests.push_back(current_test); } test_element = element->FindElement("test"); while (test_element) { - current_test = new Test; - current_test->condition = new FGCondition(test_element, PropertyManager); - value = test_element->GetAttributeValue("value"); - current_test->setTestValue(value, Name, PropertyManager, test_element); - tests.push_back(current_test); + try { + current_test = new Test; + current_test->condition = new FGCondition(test_element, PropertyManager); + value = test_element->GetAttributeValue("value"); + current_test->setTestValue(value, Name, PropertyManager, test_element); + tests.push_back(current_test); + } catch (const BaseException& e) { + FGXMLLogging log(fcs->GetExec()->GetLogger(), test_element, LogLevel::ERROR); + log << e.what() << "\n" + << " Test IGNORED.\n"; + } + test_element = element->FindNextElement("test"); } @@ -147,7 +161,7 @@ bool FGSwitch::Run(void ) break; } } - + if (!pass) Output = default_output; if (delay != 0) Delay(); @@ -177,7 +191,7 @@ void FGSwitch::VerifyProperties(void) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -194,25 +208,27 @@ void FGSwitch::Debug(int from) if (debug_lvl & 1) { // Standard console startup message output if (from == 0) { // Constructor + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); unsigned int i = 0; for (auto test: tests) { if (test->Default) { - cout << " Switch default value is: " << test->GetOutputName(); + log << " Switch default value is: " << test->GetOutputName(); } else { - cout << " Switch takes test " << i << " value (" << test->GetOutputName() << ")" << endl; + log << " Switch takes test " << i << " value (" << test->GetOutputName() << ")\n"; test->condition->PrintCondition(" "); } - cout << endl; + log << "\n"; ++i; } for (auto node: OutputNodes) - cout << " OUTPUT: " << node->getNameString() << endl; + log << " OUTPUT: " << node->getNameString() << "\n"; } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGSwitch" << endl; - if (from == 1) cout << "Destroyed: FGSwitch" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGSwitch\n"; + if (from == 1) log << "Destroyed: FGSwitch\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } @@ -227,4 +243,3 @@ void FGSwitch::Debug(int from) } } //namespace JSBSim - diff --git a/src/models/flight_control/FGSwitch.h b/src/models/flight_control/FGSwitch.h index fd78981a3..a9c454e74 100644 --- a/src/models/flight_control/FGSwitch.h +++ b/src/models/flight_control/FGSwitch.h @@ -156,11 +156,10 @@ class FGSwitch : public FGFCSComponent void setTestValue(const std::string &value, const std::string &Name, std::shared_ptr pm, Element* el) { - if (value.empty()) { - std::cerr << "No VALUE supplied for switch component: " << Name - << std::endl; - } else + if (!value.empty()) OutputValue = new FGParameterValue(value, pm, el); + else + throw BaseException("No VALUE supplied for switch component: " + Name); } std::string GetOutputName(void) const {return OutputValue->GetName();} diff --git a/src/models/flight_control/FGWaypoint.cpp b/src/models/flight_control/FGWaypoint.cpp index 84debc62d..be600a287 100644 --- a/src/models/flight_control/FGWaypoint.cpp +++ b/src/models/flight_control/FGWaypoint.cpp @@ -43,6 +43,7 @@ INCLUDES #include "models/FGFCS.h" #include "models/FGInertial.h" #include "initialization/FGInitialCondition.h" +#include "input_output/FGLog.h" using namespace std; @@ -77,10 +78,9 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) } } } else { - cerr << element->ReadFrom() << endl - << "Target latitude is required for waypoint component: " << Name - << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Target latitude is required for waypoint component: " << Name << "\n"; + throw BaseException(log.str()); } if (element->FindElement("target_longitude") ) { @@ -92,10 +92,9 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) } } } else { - cerr << element->ReadFrom() << endl - << "Target longitude is required for waypoint component: " << Name - << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Target longitude is required for waypoint component: " << Name << "\n"; + throw BaseException(log.str()); } if (element->FindElement("source_latitude") ) { @@ -107,10 +106,9 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) } } } else { - cerr << element->ReadFrom() << endl - << "Source latitude is required for waypoint component: " << Name - << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Source latitude is required for waypoint component: " << Name << "\n"; + throw BaseException(log.str()); } if (element->FindElement("source_longitude") ) { @@ -122,10 +120,9 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) } } } else { - cerr << element->ReadFrom() << endl - << "Source longitude is required for waypoint component: " << Name - << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Source longitude is required for waypoint component: " << Name << "\n"; + throw BaseException(log.str()); } unit = element->GetAttributeValue("unit"); @@ -134,10 +131,9 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) if (unit == "DEG") eUnit = eDeg; else if (unit == "RAD") eUnit = eRad; else { - cerr << element->ReadFrom() << endl - << "Unknown unit " << unit << " in HEADING waypoint component, " - << Name << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Unknown unit " << unit << " in HEADING waypoint component, " << "\n"; + throw BaseException(log.str()); } } else { eUnit = eRad; // Default is radians if unspecified @@ -147,10 +143,10 @@ FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) if (unit == "FT") eUnit = eFeet; else if (unit == "M") eUnit = eMeters; else { - cerr << element->ReadFrom() << endl - << "Unknown unit " << unit << " in DISTANCE waypoint component, " - << Name << endl; - throw("Malformed waypoint definition"); + FGXMLLogging log(fcs->GetExec()->GetLogger(), element, LogLevel::FATAL); + log << "Unknown unit " << unit << " in DISTANCE waypoint component, " + << Name << "\n"; + throw BaseException(log.str()); } } else { eUnit = eFeet; // Default is feet if unspecified @@ -179,19 +175,19 @@ bool FGWaypoint::Run(void ) source.SetPositionGeodetic(source_longitude_rad, source_latitude_rad, 0.0); if (fabs(target_latitude_rad) > M_PI/2.0) { - cerr << endl; - cerr << "Target latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl; - cerr << "(is longitude being mistakenly supplied?)" << endl; - cerr << endl; - throw("Waypoint target latitude exceeded 90 degrees."); + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::FATAL); + log << "\nTarget latitude in waypoint \"" << Name + << "\" must be less than or equal to 90 degrees.\n" + << "(is longitude being mistakenly supplied?)\n\n"; + throw BaseException(log.str()); } if (fabs(source_latitude_rad) > M_PI/2.0) { - cerr << endl; - cerr << "Source latitude in waypoint \"" << Name << "\" must be less than or equal to 90 degrees." << endl; - cerr << "(is longitude being mistakenly supplied?)" << endl; - cerr << endl; - throw("Source latitude exceeded 90 degrees."); + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::FATAL); + log << "\nSource latitude in waypoint \"" << Name + << "\" must be less than or equal to 90 degrees.\n" + << "(is longitude being mistakenly supplied?)\n\n"; + throw BaseException(log.str()); } if (WaypointType == eHeading) { // Calculate Heading @@ -225,7 +221,7 @@ bool FGWaypoint::Run(void ) // variable is not set, debug_lvl is set to 1 internally // 0: This requests JSBSim not to output any messages // whatsoever. -// 1: This value explicity requests the normal JSBSim +// 1: This value explicitly requests the normal JSBSim // startup messages // 2: This value asks for a message to be printed out when // a class is instantiated @@ -245,8 +241,9 @@ void FGWaypoint::Debug(int from) } } if (debug_lvl & 2 ) { // Instantiation/Destruction notification - if (from == 0) cout << "Instantiated: FGWaypoint" << endl; - if (from == 1) cout << "Destroyed: FGWaypoint" << endl; + FGLogging log(fcs->GetExec()->GetLogger(), LogLevel::DEBUG); + if (from == 0) log << "Instantiated: FGWaypoint\n"; + if (from == 1) log << "Destroyed: FGWaypoint\n"; } if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects }