X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Flogger.cxx;h=0e8109e0df7b8b6f8b54393d26bd3a487ce0534d;hb=52e5a9abe83882ca946429f7d8e71894d5852d8f;hp=3e42f23cbc774910284ae701a204b9f239162e28;hpb=d8a50ad49ec9b6403e6e05e14a6c50694cb42061;p=flightgear.git diff --git a/src/Main/logger.cxx b/src/Main/logger.cxx index 3e42f23cb..0e8109e0d 100644 --- a/src/Main/logger.cxx +++ b/src/Main/logger.cxx @@ -3,20 +3,21 @@ // // This file is in the Public Domain, and comes with no warranty. +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include "logger.hxx" #include -SG_USING_STD(ofstream); -SG_USING_STD(endl); - #include -SG_USING_STD(string); #include #include "fg_props.hxx" - +using std::string; +using std::endl; //////////////////////////////////////////////////////////////////////// // Implementation of FGLogger @@ -37,33 +38,74 @@ FGLogger::init () if (logging == 0) return; - vector children = logging->getChildren("log"); - for (int i = 0; i < children.size(); i++) { + std::vector children = logging->getChildren("log"); + for (unsigned int i = 0; i < children.size(); i++) { + + SGPropertyNode * child = children[i]; + + if (!child->getBoolValue("enabled", false)) + continue; + _logs.push_back(Log()); Log &log = _logs[_logs.size()-1]; - SGPropertyNode * child = children[i]; - string filename = child->getStringValue("filename", "fg_log.csv"); - log.interval_ms = child->getLongValue("interval-ms", 0); - log.delimiter = child->getStringValue("delimiter", ",")[0]; - log.output = new ofstream(filename.c_str()); + + string filename = child->getStringValue("filename"); + if (filename.empty()) { + filename = "fg_log.csv"; + child->setStringValue("filename", filename.c_str()); + } + + string delimiter = child->getStringValue("delimiter"); + if (delimiter.empty()) { + delimiter = ","; + child->setStringValue("delimiter", delimiter.c_str()); + } + + log.interval_ms = child->getLongValue("interval-ms"); + log.last_time_ms = globals->get_sim_time_sec() * 1000; + log.delimiter = delimiter.c_str()[0]; + log.output = new std::ofstream(filename.c_str()); if (!log.output) { - SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename); + SG_LOG(SG_GENERAL, SG_ALERT, "Cannot write log to " << filename); continue; } - vector entries = child->getChildren("entry"); + + // + // Process the individual entries (Time is automatic). + // + std::vector entries = child->getChildren("entry"); (*log.output) << "Time"; - for (int j = 0; j < entries.size(); j++) { + for (unsigned int j = 0; j < entries.size(); j++) { SGPropertyNode * entry = entries[j]; + + // + // Set up defaults. + // + if (!entry->hasValue("property")) { + entry->setBoolValue("enabled", false); + continue; + } + + if (!entry->getBoolValue("enabled")) + continue; + SGPropertyNode * node = fgGetNode(entry->getStringValue("property"), true); log.nodes.push_back(node); (*log.output) << log.delimiter - << entry->getStringValue("title", node->getPath()); + << entry->getStringValue("title", node->getPath().c_str()); } (*log.output) << endl; } } +void +FGLogger::reinit () +{ + _logs.clear(); + init(); +} + void FGLogger::bind () { @@ -75,20 +117,21 @@ FGLogger::unbind () } void -FGLogger::update (int dt) +FGLogger::update (double dt) { - long elapsed_ms = globals->get_elapsed_time_ms(); - for (int i = 0; i < _logs.size(); i++) { - if ((elapsed_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) { - _logs[i].last_time_ms = elapsed_ms; - (*_logs[i].output) << globals->get_elapsed_time_ms(); - for (int j = 0; j < _logs[i].nodes.size(); j++) { - (*_logs[i].output) << _logs[i].delimiter + double sim_time_sec = globals->get_sim_time_sec(); + double sim_time_ms = sim_time_sec * 1000; + for (unsigned int i = 0; i < _logs.size(); i++) { + while ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) { + _logs[i].last_time_ms += _logs[i].interval_ms; + (*_logs[i].output) << sim_time_sec; + for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) { + (*_logs[i].output) << _logs[i].delimiter << _logs[i].nodes[j]->getStringValue(); - } - (*_logs[i].output) << endl; + } + (*_logs[i].output) << endl; + } } - } } @@ -100,7 +143,7 @@ FGLogger::update (int dt) FGLogger::Log::Log () : output(0), interval_ms(0), - last_time_ms(-999999L), + last_time_ms(-999999.0), delimiter(',') { }