From 19aa0332f2c27d24cb0c0eafa0569ed17d0ed3ce Mon Sep 17 00:00:00 2001 From: Automatic Release Builder <build@flightgear.org> Date: Thu, 8 Oct 2020 09:16:00 +0100 Subject: [PATCH] =?UTF-8?q?loadxml()=20command:=20add=20=E2=80=98quiet?= =?UTF-8?q?=E2=80=99=20bool=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to avoid console/log spam from jetways.nas in particular, which uses loadxml to probe for file existence, every 10 seconds. But in general it seems useful to have this potentially be quiet, since there is a result code. --- src/Main/fg_commands.cxx | 24 ++++++++++++++++-------- src/Scripting/NasalSys.cxx | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 6405fd3ce..4d1650ea4 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -735,6 +735,10 @@ do_load_xml_to_proptree(const SGPropertyNode * arg, SGPropertyNode * root) if (file.extension() != "xml") file.concat(".xml"); + // some Nasal uses loadxml to also speculatively probe for existence of + // files. This flag allows us not to be noisy in the logs, in that case. + const bool quiet = arg->getBoolValue("quiet", false); + std::string icao = arg->getStringValue("icao"); if (icao.empty()) { if (file.isRelative()) { @@ -743,28 +747,32 @@ do_load_xml_to_proptree(const SGPropertyNode * arg, SGPropertyNode * root) file = absPath; else { - SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '" - << file << "'."); + if (!quiet) { + SG_LOG(SG_IO, SG_ALERT, "loadxml: Cannot find XML property file '" << file << "'."); + } return false; } } } else { if (!XMLLoader::findAirportData(icao, file.utf8Str(), file)) { - SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for " - << file << " at ICAO:" << icao); + if (!quiet) { + SG_LOG(SG_IO, SG_INFO, "loadxml: failed to find airport data for " << file << " at ICAO:" << icao); + } return false; } } if (!file.exists()) { - SG_LOG(SG_IO, SG_WARN, "loadxml: no such file:" << file); + if (!quiet) { + SG_LOG(SG_IO, SG_WARN, "loadxml: no such file:" << file); + } return false; } SGPath validated_path = fgValidatePath(file, false); if (validated_path.isNull()) { - SG_LOG(SG_IO, SG_ALERT, "loadxml: reading '" << file << "' denied " - "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, pass them to --allow-nasal-read)"); + SG_LOG(SG_IO, quiet ? SG_DEV_WARN : SG_ALERT, "loadxml: reading '" << file << "' denied " + "(unauthorized directory - authorization no longer follows symlinks; to authorize reading additional directories, pass them to --allow-nasal-read)"); return false; } @@ -777,7 +785,7 @@ do_load_xml_to_proptree(const SGPropertyNode * arg, SGPropertyNode * root) try { readProperties(validated_path, targetnode, true); } catch (const sg_exception &e) { - SG_LOG(SG_IO, SG_WARN, "loadxml exception: " << e.getFormattedMessage()); + SG_LOG(SG_IO, quiet ? SG_DEV_WARN : SG_WARN, "loadxml exception: " << e.getFormattedMessage()); return false; } diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 53f1e0a33..ab909aea5 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -882,7 +882,7 @@ static naRef ftype(naContext ctx, const SGPath& f) } // io.stat with UTF-8 path support, replaces the default one in -// Nasal iolib.c which does not hsupport UTF-8 paths +// Nasal iolib.c which does not support UTF-8 paths static naRef f_custom_stat(naContext ctx, naRef me, int argc, naRef* args) { naRef pathArg = argc > 0 ? naStringValue(ctx, args[0]) : naNil();