Skip to content

Commit

Permalink
Fixes to the logging code (#1141)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni authored Aug 17, 2024
1 parent 0b99bf8 commit 42562f7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/FGFDMExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,8 +1417,7 @@ void FGFDMExec::Debug(int from)
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
if (from == 2) {
FGLogging log(Log, LogLevel::DEBUG);
log << "================== Frame: " << Frame << " Time: "
log << "================== Frame: " << Frame << " Time: " << fixed
<< sim_time << " dt: " << dT << endl;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/FGFDMExec.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,10 @@ class JSBSIM_API FGFDMExec : public FGJSBBase
auto GetRandomGenerator(void) const { return RandomGenerator; }

private:
// Declare Log first so that it's destroyed last: the logger may be used by
// some FGFDMExec members to log data during their destruction.
std::shared_ptr<FGLogger> Log;

unsigned int Frame;
unsigned int IdFDM;
int disperse;
Expand Down Expand Up @@ -697,8 +701,6 @@ class JSBSIM_API FGFDMExec : public FGJSBBase
std::vector <std::shared_ptr<FGModel>> Models;
std::map<std::string, FGTemplateFunc_ptr> TemplateFunctions;

std::shared_ptr<FGLogger> Log;

bool ReadFileHeader(Element*);
bool ReadChild(Element*);
bool ReadPrologue(Element*);
Expand Down
2 changes: 1 addition & 1 deletion src/initialization/FGTrimAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ void FGTrimAxis::AxisReport(void) {
std::ios_base::fmtflags originalFormat = cout.flags();
std::streamsize originalPrecision = cout.precision();
std::streamsize originalWidth = cout.width();
cout << " " << setw(20) << GetControlName() << ": ";
cout << " " << left << setw(20) << GetControlName() << ": ";
cout << setw(6) << setprecision(2) << GetControl()*control_convert << ' ';
cout << setw(5) << GetStateName() << ": ";
cout << setw(9) << setprecision(2) << scientific << GetState()+state_target;
Expand Down
1 change: 0 additions & 1 deletion src/input_output/FGLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void FGLogging::Flush(void)
if (!message.empty()) {
logger->Message(message);
buffer.str("");
logger->Format(LogFormat::RESET);
logger->Flush();
}

Expand Down
4 changes: 2 additions & 2 deletions src/models/FGMassBalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void FGMassBalance::GetMassPropertiesReport(int i)
log << " " << LogFormat::UNDERLINE_ON << " Weight CG-X CG-Y"
<< " CG-Z Ixx Iyy Izz"
<< " Ixy Ixz Iyz" << LogFormat::UNDERLINE_OFF << endl;
log << setprecision(1);
log << fixed << setprecision(1);
log << LogFormat::BOLD << setw(34) << left << " Base Vehicle " << normint
<< right << setw(12) << EmptyWeight
<< setw(8) << vbaseXYZcg(eX) << setw(8) << vbaseXYZcg(eY) << setw(8) << vbaseXYZcg(eZ)
Expand Down Expand Up @@ -516,7 +516,7 @@ void FGMassBalance::Debug(int from)
if (debug_lvl & 1) { // Standard console startup message output
if (from == 2) { // Loading
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
log << endl << " Mass and Balance:" << endl;
log << endl << " Mass and Balance:" << endl << fixed;
log << " baseIxx: " << baseJ(1,1) << " slug-ft2" << endl;
log << " baseIyy: " << baseJ(2,2) << " slug-ft2" << endl;
log << " baseIzz: " << baseJ(3,3) << " slug-ft2" << endl;
Expand Down
6 changes: 3 additions & 3 deletions src/models/FGModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ bool FGModel::InitModel(void)

bool FGModel::Run(bool Holding)
{
FGModel::Debug(2);

if (rate == 1) return false; // Fast exit if nothing to do

if (exe_ctr >= rate) exe_ctr = 0;

if (exe_ctr++ == 1) return false;
else return true;

Debug(2);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down Expand Up @@ -184,7 +184,7 @@ void FGModel::Debug(int from)
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
log << "Entering Run() for model " << Name << endl;
if (from ==2) log << "Entering Run() for model " << Name << endl;
}
if (debug_lvl & 8 ) { // Runtime state variables
}
Expand Down
7 changes: 2 additions & 5 deletions src/models/FGPropagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ CLASS IMPLEMENTATION
FGPropagate::FGPropagate(FGFDMExec* fdmex)
: FGModel(fdmex)
{
Debug(0);
Name = "FGPropagate";

Inertial = FDMExec->GetInertial();
Expand Down Expand Up @@ -707,7 +706,7 @@ void FGPropagate::DumpState(void)
log << endl;
log << LogFormat::BLUE
<< "------------------------------------------------------------------" << LogFormat::RESET << endl;
log << LogFormat::BOLD
log << LogFormat::BOLD << fixed
<< "State Report at sim time: " << FDMExec->GetSimTime() << " seconds" << LogFormat::RESET << endl;
log << " " << LogFormat::UNDERLINE_ON
<< "Position" << LogFormat::UNDERLINE_OFF << endl;
Expand Down Expand Up @@ -945,7 +944,7 @@ void FGPropagate::Debug(int from)
}
if (debug_lvl & 8 && from == 2) { // Runtime state variables
FGLogging log(FDMExec->GetLogger(), LogLevel::DEBUG);
log << endl << LogFormat::BLUE << LogFormat::BOLD << left
log << endl << LogFormat::BLUE << LogFormat::BOLD << left << fixed
<< " Propagation Report (English units: ft, degrees) at simulation time " << FDMExec->GetSimTime() << " seconds"
<< LogFormat::RESET << endl;
log << endl;
Expand Down Expand Up @@ -1032,8 +1031,6 @@ void FGPropagate::Debug(int from)
log << LogFormat::BOLD << " Associated Euler angles (deg): " << setw(8)
<< setprecision(3) << LogFormat::RESET << (Tl2i.GetQuaternion().GetEuler()*radtodeg)
<< endl << endl;

log << setprecision(6); // reset the output stream
}
if (debug_lvl & 16) { // Sanity checking
if (from == 2) { // State sanity checking
Expand Down

0 comments on commit 42562f7

Please sign in to comment.