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 SG_USING_STD(ofstream);
15 #include <simgear/debug/logstream.hxx>
17 #include "fg_props.hxx"
21 ////////////////////////////////////////////////////////////////////////
22 // Implementation of FGLogger
23 ////////////////////////////////////////////////////////////////////////
29 FGLogger::~FGLogger ()
36 SGPropertyNode * logging = fgGetNode("/logging");
40 vector<SGPropertyNode *> children = logging->getChildren("log");
41 for (int i = 0; i < children.size(); i++) {
42 _logs.push_back(Log());
43 Log &log = _logs[_logs.size()-1];
44 SGPropertyNode * child = children[i];
45 string filename = child->getStringValue("filename", "fg_log.csv");
46 log.interval_ms = child->getLongValue("interval-ms", 0);
47 log.output = new ofstream(filename.c_str());
49 SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
52 vector<SGPropertyNode *> entries = child->getChildren("entry");
53 (*log.output) << "Time";
54 for (int j = 0; j < entries.size(); j++) {
55 SGPropertyNode * entry = entries[j];
56 SGPropertyNode * node =
57 fgGetNode(entry->getStringValue("property"), true);
58 log.nodes.push_back(node);
60 << entry->getStringValue("title", node->getPath());
62 (*log.output) << endl;
77 FGLogger::update (int dt)
79 long elapsed_ms = globals->get_elapsed_time_ms();
80 for (int i = 0; i < _logs.size(); i++) {
81 if ((elapsed_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
82 _logs[i].last_time_ms = elapsed_ms;
83 (*_logs[i].output) << globals->get_elapsed_time_ms();
84 for (int j = 0; j < _logs[i].nodes.size(); j++) {
85 (*_logs[i].output) << ',' << _logs[i].nodes[j]->getStringValue();
87 (*_logs[i].output) << endl;
94 ////////////////////////////////////////////////////////////////////////
95 // Implementation of FGLogger::Log
96 ////////////////////////////////////////////////////////////////////////
101 last_time_ms(-99999999999999L)
105 FGLogger::Log::~Log ()