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.
11 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_ptr> children = logging->getChildren("log");
41 for (unsigned 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.delimiter = child->getStringValue("delimiter", ",")[0];
48 log.output = new ofstream(filename.c_str());
50 SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
53 vector<SGPropertyNode_ptr> entries = child->getChildren("entry");
54 (*log.output) << "Time";
55 for (unsigned int j = 0; j < entries.size(); j++) {
56 SGPropertyNode * entry = entries[j];
57 SGPropertyNode * node =
58 fgGetNode(entry->getStringValue("property"), true);
59 log.nodes.push_back(node);
60 (*log.output) << log.delimiter
61 << entry->getStringValue("title", node->getPath());
63 (*log.output) << endl;
78 FGLogger::update (double dt)
80 double sim_time_ms = globals->get_sim_time_sec() * 1000;
81 for (unsigned int i = 0; i < _logs.size(); i++) {
82 if ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
83 _logs[i].last_time_ms = sim_time_ms;
84 (*_logs[i].output) << sim_time_ms;
85 for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
86 (*_logs[i].output) << _logs[i].delimiter
87 << _logs[i].nodes[j]->getStringValue();
89 (*_logs[i].output) << endl;
96 ////////////////////////////////////////////////////////////////////////
97 // Implementation of FGLogger::Log
98 ////////////////////////////////////////////////////////////////////////
100 FGLogger::Log::Log ()
103 last_time_ms(-999999.0),
108 FGLogger::Log::~Log ()