From 2566a1abf52b65a4a0f3a0eb951dbbf57169307a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 7 Jan 2024 22:31:52 +0100 Subject: [PATCH] Add wxLogFormatterNone This trivial class allows to easily disable all log formatting, including time stamping and level-dependent prefixes. --- include/wx/log.h | 13 +++++++++++++ interface/wx/log.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/wx/log.h b/include/wx/log.h index 8e1e01b25a..724d80aae5 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -341,6 +341,19 @@ protected: #endif // WXWIN_COMPATIBILITY_3_0 }; +// Special kind of trivial formatter which simply uses the message unchanged. +class wxLogFormatterNone : public wxLogFormatter +{ +public: + wxLogFormatterNone() = default; + + virtual wxString Format(wxLogLevel WXUNUSED(level), + const wxString& msg, + const wxLogRecordInfo& WXUNUSED(info)) const override + { + return msg; + } +}; // ---------------------------------------------------------------------------- // derive from this class to redirect (or suppress, or ...) log messages diff --git a/interface/wx/log.h b/interface/wx/log.h index 087f31b665..e65691c3a3 100644 --- a/interface/wx/log.h +++ b/interface/wx/log.h @@ -115,6 +115,9 @@ public: [7872] d:\testApp\src\testApp.cpp(85) : *** Application started *** @endverbatim + See wxLogFormatterNone for a trivial version of this class not doing any + formatting, + @library{wxbase} @category{logging} @@ -195,6 +198,31 @@ protected: }; +/** + Specialized formatter not formatting the messages at all. + + This class can be used to make wxLog log just the messages themselves, + without any time stamps or prefixes indicating their severity. + + Example of using it: + + @code + wxLog* logger = wxLog::GetActiveTarget(); + delete logger->SetFormatter(new wxLogFormatterNone{}); + + // Log messages won't have time stamps or "Error:", "Warning:" etc + // prefixes any more. + @endcode + + @since 3.3.0 +*/ +class wxLogFormatterNone : public wxLogFormatter +{ +public: + /// Trivial default constructor. + wxLogFormatterNone(); +}; + /** @class wxLog