From 3a73933cf1617927d0b66aece2c37bca22d2c2d9 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Sun, 19 Jan 2020 22:16:31 +0000 Subject: [PATCH] [xswiftbus] Stop logging probe failures after a certain number To avoid flooding the log with messages. --- src/xswiftbus/terrainprobe.cpp | 17 +++++++++++------ src/xswiftbus/terrainprobe.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/xswiftbus/terrainprobe.cpp b/src/xswiftbus/terrainprobe.cpp index baee8a3db..07b1e9c48 100644 --- a/src/xswiftbus/terrainprobe.cpp +++ b/src/xswiftbus/terrainprobe.cpp @@ -27,16 +27,21 @@ namespace XSwiftBus auto result = XPLMProbeTerrainXYZ(m_ref, static_cast(x), static_cast(y), static_cast(z), &probe); if (result != xplm_ProbeHitTerrain) { - std::string error; - if (result == xplm_ProbeError) { error = "probe error"; } - else if (result == xplm_ProbeMissed) { error = "probe missed"; } - else { error = "unknown probe result"; } - WARNING_LOG(callsign + " " + error + " at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude)); + if (m_logMessageCount < 100) + { + m_logMessageCount++; + std::string error; + if (result == xplm_ProbeError) { error = "probe error"; } + else if (result == xplm_ProbeMissed) { error = "probe missed"; } + else { error = "unknown probe result"; } + WARNING_LOG(callsign + " " + error + " at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude)); + } return std::numeric_limits::quiet_NaN(); } - if (probe.is_wet) + if (probe.is_wet && m_logMessageCount < 100) { + m_logMessageCount++; DEBUG_LOG(callsign + " probe hit water at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude)); } diff --git a/src/xswiftbus/terrainprobe.h b/src/xswiftbus/terrainprobe.h index 55c301077..2a9f6e368 100644 --- a/src/xswiftbus/terrainprobe.h +++ b/src/xswiftbus/terrainprobe.h @@ -39,6 +39,7 @@ namespace XSwiftBus private: XPLMProbeRef m_ref = nullptr; + mutable int m_logMessageCount = 0; }; } // ns