From 2f93592c6f744aa10fc10a75fa6392ad6ae92a9d Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 21 Mar 2023 21:33:28 +0100 Subject: [PATCH] Reporter: Add dedicated Deprecation() method Minimally, provide a way to funnel all deprecations through reporter->Deprecation() instead of various Warning() invocations. --- src/Reporter.cc | 17 +++++++++++++++++ src/Reporter.h | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Reporter.cc b/src/Reporter.cc index 039ec69f53..6815dbe4b2 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -59,6 +59,8 @@ Reporter::Reporter(bool arg_abort_on_scripting_errors) weird_sampling_duration = 0; weird_sampling_threshold = 0; + ignore_deprecations = false; + syslog_open = false; } @@ -532,6 +534,21 @@ void Reporter::Weird(const IPAddr& orig, const IPAddr& resp, const char* name, c "%s", name); } +void Reporter::Deprecation(std::string_view msg, const detail::Location* loc1, + const detail::Location* loc2) + { + if ( ignore_deprecations ) + return; + + if ( loc1 || loc2 ) + PushLocation(loc1, loc2); + + Warning("%s", msg.data()); + + if ( loc1 || loc2 ) + PopLocation(); + } + void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out, Connection* conn, ValPList* addl, bool location, bool time, const char* postfix, const char* fmt, va_list ap) diff --git a/src/Reporter.h b/src/Reporter.h index 12ed830f00..c243d6e98d 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -133,6 +133,13 @@ public: void Weird(const IPAddr& orig, const IPAddr& resp, const char* name, const char* addl = "", const char* source = ""); // Raises flow_weird(). + // Report a deprecation. The message should contain a version. + void Deprecation(std::string_view msg, const detail::Location* loc1 = nullptr, + const detail::Location* loc2 = nullptr); + + // Whether or not deprecations are logged when calling Deprecation() + void SetIgnoreDeprecations(bool arg) { ignore_deprecations = arg; } + // Syslog a message. This methods does nothing if we're running // offline from a trace. void Syslog(const char* fmt, ...) FMT_ATTR; @@ -345,6 +352,8 @@ private: uint64_t weird_sampling_threshold; uint64_t weird_sampling_rate; double weird_sampling_duration; + + bool ignore_deprecations; }; extern Reporter* reporter;