1 // logger.cxx - log properties.
2 // Written by David Megginson, started 2002.
4 // This file is in the Public Domain, and comes with no warranty.
9 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
10 SG_USING_STD(ofstream);
17 #include <simgear/debug/logstream.hxx>
19 #include "fg_props.hxx"
23 ////////////////////////////////////////////////////////////////////////
24 // Implementation of FGLogger
25 ////////////////////////////////////////////////////////////////////////
31 FGLogger::~FGLogger ()
38 SGPropertyNode * logging = fgGetNode("/logging");
42 vector<SGPropertyNode *> children = logging->getChildren("log");
43 for (unsigned int i = 0; i < children.size(); i++) {
44 _logs.push_back(Log());
45 Log &log = _logs[_logs.size()-1];
46 SGPropertyNode * child = children[i];
47 string filename = child->getStringValue("filename", "fg_log.csv");
48 log.interval_ms = child->getLongValue("interval-ms", 0);
49 log.delimiter = child->getStringValue("delimiter", ",")[0];
50 log.output = new ofstream(filename.c_str());
52 SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
55 vector<SGPropertyNode *> entries = child->getChildren("entry");
56 (*log.output) << "Time";
57 for (unsigned int j = 0; j < entries.size(); j++) {
58 SGPropertyNode * entry = entries[j];
59 SGPropertyNode * node =
60 fgGetNode(entry->getStringValue("property"), true);
61 log.nodes.push_back(node);
62 (*log.output) << log.delimiter
63 << entry->getStringValue("title", node->getPath());
65 (*log.output) << endl;
80 FGLogger::update (int dt)
82 double sim_time_ms = globals->get_sim_time_ms();
83 for (unsigned int i = 0; i < _logs.size(); i++) {
84 if ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
85 _logs[i].last_time_ms = sim_time_ms;
86 (*_logs[i].output) << globals->get_sim_time_ms();
87 for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
88 (*_logs[i].output) << _logs[i].delimiter
89 << _logs[i].nodes[j]->getStringValue();
91 (*_logs[i].output) << endl;
98 ////////////////////////////////////////////////////////////////////////
99 // Implementation of FGLogger::Log
100 ////////////////////////////////////////////////////////////////////////
102 FGLogger::Log::Log ()
105 last_time_ms(-999999.0),
110 FGLogger::Log::~Log ()