Add wxLogFormatterNone

This trivial class allows to easily disable all log formatting,
including time stamping and level-dependent prefixes.
This commit is contained in:
Vadim Zeitlin 2024-01-07 22:31:52 +01:00
parent 30dd7e9095
commit 2566a1abf5
2 changed files with 41 additions and 0 deletions

View file

@ -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

View file

@ -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