Minor logging changes.
All logs and log entries are now disabled by default, unless explicitly enabled by an 'enabled' property. This works much more intuitively with the GUI dialog.
This commit is contained in:
parent
603834ccf1
commit
8506e731a2
3 changed files with 65 additions and 20 deletions
|
@ -15,36 +15,40 @@ anyway) as the field delimiter:
|
||||||
|
|
||||||
<logging>
|
<logging>
|
||||||
<log>
|
<log>
|
||||||
|
<enabled>true<enabled>
|
||||||
<filename>steering.csv</filename>
|
<filename>steering.csv</filename>
|
||||||
<interval-ms>1000</interval-ms>
|
<interval-ms>1000</interval-ms>
|
||||||
<delimiter>,</delimiter>
|
<delimiter>,</delimiter>
|
||||||
<entry>
|
<entry>
|
||||||
|
<enabled>true</enabled>
|
||||||
<title>Rudder</title>
|
<title>Rudder</title>
|
||||||
<property>/controls/rudder</property>
|
<property>/controls/rudder</property>
|
||||||
</entry>
|
</entry>
|
||||||
<entry>
|
<entry>
|
||||||
|
<enabled>true</enabled>
|
||||||
<title>Ailerons</title>
|
<title>Ailerons</title>
|
||||||
<property>/controls/aileron</property>
|
<property>/controls/aileron</property>
|
||||||
</entry>
|
</entry>
|
||||||
</log>
|
</log>
|
||||||
</logging>
|
</logging>
|
||||||
|
|
||||||
Each 'log' subbranch contains an optional 'filename' property
|
Each 'log' subbranch contains a required 'enabled' property, an
|
||||||
(defaults to "fg_log.csv"), an optional 'delimiter' property (defaults
|
optional 'filename' property (defaults to "fg_log.csv"), an optional
|
||||||
to a comma), an optional 'interval-ms' property (defaults to 0, which
|
'delimiter' property (defaults to a comma), an optional 'interval-ms'
|
||||||
logs every frame), and a series of 'entry' subbranches. The
|
property (defaults to 0, which logs every frame), and a series of
|
||||||
'delimiter' property uses only the first character of the property
|
'entry' subbranches. The 'delimiter' property uses only the first
|
||||||
value as the delimiter. Note that the logger does no escaping, so you
|
character of the property value as the delimiter. Note that the
|
||||||
must choose a delimiter that will not appear in the property values
|
logger does no escaping, so you must choose a delimiter that will not
|
||||||
(that's not hard, since most of the values are numeric, but watch for
|
appear in the property values (that's not hard, since most of the
|
||||||
commas in the titles).
|
values are numeric, but watch for commas in the titles).
|
||||||
|
|
||||||
Each 'entry' subbranch contains a 'property' property specifying the
|
Each 'entry' subbranch contains a required 'enabled' property, a
|
||||||
name of the property to be logged, and an optional 'title' property
|
'property' property specifying the name of the property to be logged,
|
||||||
specifying the title to use in the CSV file (defaults to the full path
|
and an optional 'title' property specifying the title to use in the
|
||||||
of the property). The elapsed time in milliseconds since the start of
|
CSV file (defaults to the full path of the property). The elapsed
|
||||||
the simulation is always included as the first entry with the title
|
time in milliseconds since the start of the simulation is always
|
||||||
"Time", so there is no need to include it explicitly.
|
included as the first entry with the title "Time", so there is no need
|
||||||
|
to include it explicitly.
|
||||||
|
|
||||||
Here's a sample of the logging output for the above log:
|
Here's a sample of the logging output for the above log:
|
||||||
|
|
||||||
|
@ -79,4 +83,4 @@ The output log files are always relative to the current directory.
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
||||||
David Megginson, 2002-03-12
|
David Megginson, last updated 2002-02-01
|
||||||
|
|
|
@ -39,21 +39,54 @@ FGLogger::init ()
|
||||||
|
|
||||||
vector<SGPropertyNode_ptr> children = logging->getChildren("log");
|
vector<SGPropertyNode_ptr> children = logging->getChildren("log");
|
||||||
for (unsigned int i = 0; i < children.size(); i++) {
|
for (unsigned int i = 0; i < children.size(); i++) {
|
||||||
|
|
||||||
|
SGPropertyNode * child = children[i];
|
||||||
|
|
||||||
|
if (!child->getBoolValue("enabled", false))
|
||||||
|
continue;
|
||||||
|
|
||||||
_logs.push_back(Log());
|
_logs.push_back(Log());
|
||||||
Log &log = _logs[_logs.size()-1];
|
Log &log = _logs[_logs.size()-1];
|
||||||
SGPropertyNode * child = children[i];
|
|
||||||
string filename = child->getStringValue("filename", "fg_log.csv");
|
string filename = child->getStringValue("filename");
|
||||||
log.interval_ms = child->getLongValue("interval-ms", 0);
|
if (filename.size() == 0) {
|
||||||
log.delimiter = child->getStringValue("delimiter", ",")[0];
|
filename = "fg_log.csv";
|
||||||
|
child->setStringValue("filename", filename.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
string delimiter = child->getStringValue("delimiter");
|
||||||
|
if (delimiter.size() == 0) {
|
||||||
|
delimiter = ",";
|
||||||
|
child->setStringValue("delimiter", delimiter.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
log.interval_ms = child->getLongValue("interval-ms");
|
||||||
|
log.delimiter = delimiter.c_str()[0];
|
||||||
log.output = new ofstream(filename.c_str());
|
log.output = new ofstream(filename.c_str());
|
||||||
if (!log.output) {
|
if (!log.output) {
|
||||||
SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
|
SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Process the individual entries (Time is automatic).
|
||||||
|
//
|
||||||
vector<SGPropertyNode_ptr> entries = child->getChildren("entry");
|
vector<SGPropertyNode_ptr> entries = child->getChildren("entry");
|
||||||
(*log.output) << "Time";
|
(*log.output) << "Time";
|
||||||
for (unsigned int j = 0; j < entries.size(); j++) {
|
for (unsigned int j = 0; j < entries.size(); j++) {
|
||||||
SGPropertyNode * entry = entries[j];
|
SGPropertyNode * entry = entries[j];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set up defaults.
|
||||||
|
//
|
||||||
|
if (!entry->hasValue("property")) {
|
||||||
|
entry->setBoolValue("enabled", false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entry->getBoolValue("enabled"))
|
||||||
|
continue;
|
||||||
|
|
||||||
SGPropertyNode * node =
|
SGPropertyNode * node =
|
||||||
fgGetNode(entry->getStringValue("property"), true);
|
fgGetNode(entry->getStringValue("property"), true);
|
||||||
log.nodes.push_back(node);
|
log.nodes.push_back(node);
|
||||||
|
@ -64,6 +97,13 @@ FGLogger::init ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
FGLogger::reinit ()
|
||||||
|
{
|
||||||
|
_logs.clear();
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
FGLogger::bind ()
|
FGLogger::bind ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,6 +40,7 @@ public:
|
||||||
|
|
||||||
// Implementation of FGSubsystem
|
// Implementation of FGSubsystem
|
||||||
virtual void init ();
|
virtual void init ();
|
||||||
|
virtual void reinit ();
|
||||||
virtual void bind ();
|
virtual void bind ();
|
||||||
virtual void unbind ();
|
virtual void unbind ();
|
||||||
virtual void update (double dt);
|
virtual void update (double dt);
|
||||||
|
|
Loading…
Reference in a new issue