34 SGPropertyNode * logging =
fgGetNode(
"/logging");
38 std::vector<SGPropertyNode_ptr> children = logging->getChildren(
"log");
39 _logs.reserve(children.size());
41 for (
const auto& child: children) {
42 if (!child->getBoolValue(
"enabled",
false))
45 string filename = child->getStringValue(
"filename");
46 if (filename.empty()) {
47 filename =
"fg_log.csv";
48 child->setStringValue(
"filename", filename.c_str());
53 const SGPath authorizedPath = SGPath::fromUtf8(filename).validate(
56 if (authorizedPath.isNull()) {
57 const string propertyPath = child->getChild(
"filename")
60 "The FGLogger logging system, via the '" + propertyPath +
"' property, "
61 "was asked to write to '" + filename +
"', however this path is not "
62 "authorized for writing anymore for security reasons. " +
63 "Please choose another location, for instance in the $FG_HOME/Export "
64 "folder (" + (
globals->get_fg_home() /
"Export").utf8Str() +
").";
66 SG_LOG(SG_GENERAL, SG_ALERT, msg);
70 _logs.emplace_back(
new Log());
71 Log &log = *_logs.back();
73 string delimiter = child->getStringValue(
"delimiter");
74 if (delimiter.empty()) {
76 child->setStringValue(
"delimiter", delimiter.c_str());
79 log.interval_ms = child->getLongValue(
"interval-ms");
80 log.last_time_ms =
globals->get_sim_time_sec() * 1000;
81 log.delimiter = delimiter.c_str()[0];
83 log.output.reset(
new sg_ofstream(authorizedPath, std::ios_base::out));
84 if ( !(*log.output) ) {
85 SG_LOG(SG_GENERAL, SG_ALERT,
"Cannot write log to " << filename);
93 std::vector<SGPropertyNode_ptr> entries = child->getChildren(
"entry");
94 (*log.output) <<
"Time";
95 for (
unsigned int j = 0; j < entries.size(); j++) {
96 SGPropertyNode * entry = entries[j];
101 if (!entry->hasValue(
"property")) {
102 entry->setBoolValue(
"enabled",
false);
106 if (!entry->getBoolValue(
"enabled"))
109 SGPropertyNode * node =
110 fgGetNode(entry->getStringValue(
"property"),
true);
111 log.nodes.push_back(node);
112 (*log.output) << log.delimiter
113 << entry->getStringValue(
"title", node->getPath().c_str());
115 (*log.output) << endl;