2002-03-12 16:29:00 +00:00
|
|
|
|
// logger.cxx - log properties.
|
|
|
|
|
// Written by David Megginson, started 2002.
|
|
|
|
|
//
|
|
|
|
|
// This file is in the Public Domain, and comes with no warranty.
|
|
|
|
|
|
|
|
|
|
#include "logger.hxx"
|
|
|
|
|
|
2002-03-12 20:01:54 +00:00
|
|
|
|
#include STL_FSTREAM
|
|
|
|
|
#ifndef SG_HAVE_NATIVE_SGI_COMPILERS
|
2002-03-12 16:29:00 +00:00
|
|
|
|
SG_USING_STD(ofstream);
|
|
|
|
|
SG_USING_STD(endl);
|
2002-03-12 20:01:54 +00:00
|
|
|
|
#endif
|
2002-03-12 16:29:00 +00:00
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
SG_USING_STD(string);
|
|
|
|
|
|
|
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
|
|
|
|
|
|
#include "fg_props.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGLogger
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGLogger::FGLogger ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGLogger::~FGLogger ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGLogger::init ()
|
|
|
|
|
{
|
|
|
|
|
SGPropertyNode * logging = fgGetNode("/logging");
|
|
|
|
|
if (logging == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-05-11 00:59:26 +00:00
|
|
|
|
vector<SGPropertyNode_ptr> children = logging->getChildren("log");
|
2002-03-13 17:06:17 +00:00
|
|
|
|
for (unsigned int i = 0; i < children.size(); i++) {
|
2002-03-12 16:29:00 +00:00
|
|
|
|
_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);
|
2002-03-12 19:55:49 +00:00
|
|
|
|
log.delimiter = child->getStringValue("delimiter", ",")[0];
|
2002-03-12 16:29:00 +00:00
|
|
|
|
log.output = new ofstream(filename.c_str());
|
|
|
|
|
if (!log.output) {
|
|
|
|
|
SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2002-05-11 00:59:26 +00:00
|
|
|
|
vector<SGPropertyNode_ptr> entries = child->getChildren("entry");
|
2002-03-12 16:29:00 +00:00
|
|
|
|
(*log.output) << "Time";
|
2002-03-13 17:06:17 +00:00
|
|
|
|
for (unsigned int j = 0; j < entries.size(); j++) {
|
2002-03-12 16:29:00 +00:00
|
|
|
|
SGPropertyNode * entry = entries[j];
|
|
|
|
|
SGPropertyNode * node =
|
|
|
|
|
fgGetNode(entry->getStringValue("property"), true);
|
|
|
|
|
log.nodes.push_back(node);
|
2002-03-12 19:55:49 +00:00
|
|
|
|
(*log.output) << log.delimiter
|
2002-03-12 16:29:00 +00:00
|
|
|
|
<< entry->getStringValue("title", node->getPath());
|
|
|
|
|
}
|
|
|
|
|
(*log.output) << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGLogger::bind ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGLogger::unbind ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
FGLogger::update (int dt)
|
|
|
|
|
{
|
2002-04-20 14:52:43 +00:00
|
|
|
|
double sim_time_ms = globals->get_sim_time_ms();
|
2002-03-13 17:06:17 +00:00
|
|
|
|
for (unsigned int i = 0; i < _logs.size(); i++) {
|
2002-04-20 14:52:43 +00:00
|
|
|
|
if ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
|
|
|
|
|
_logs[i].last_time_ms = sim_time_ms;
|
|
|
|
|
(*_logs[i].output) << globals->get_sim_time_ms();
|
2002-03-13 17:06:17 +00:00
|
|
|
|
for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
|
2002-03-12 19:55:49 +00:00
|
|
|
|
(*_logs[i].output) << _logs[i].delimiter
|
|
|
|
|
<< _logs[i].nodes[j]->getStringValue();
|
2002-03-12 16:29:00 +00:00
|
|
|
|
}
|
|
|
|
|
(*_logs[i].output) << endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Implementation of FGLogger::Log
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FGLogger::Log::Log ()
|
|
|
|
|
: output(0),
|
|
|
|
|
interval_ms(0),
|
2002-04-20 14:52:43 +00:00
|
|
|
|
last_time_ms(-999999.0),
|
2002-03-12 19:55:49 +00:00
|
|
|
|
delimiter(',')
|
2002-03-12 16:29:00 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FGLogger::Log::~Log ()
|
|
|
|
|
{
|
|
|
|
|
delete output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// end of logger.cxx
|