diff --git a/include/wx/gtk/private/log.h b/include/wx/gtk/private/log.h index c8c745a76c..662342e373 100644 --- a/include/wx/gtk/private/log.h +++ b/include/wx/gtk/private/log.h @@ -34,8 +34,8 @@ public: } // Function to call to install this filter as the active one. - // Does nothing if run-time glib version is too old. - void Install(); + // Does nothing and just returns false if run-time glib version is too old. + bool Install(); protected: // Function to override in the derived class to actually filter: return @@ -104,10 +104,15 @@ public: explicit LogFilterByMessage(const char* message) : m_message(message) { - Install(); + // We shouldn't warn about anything if Install() failed. + m_warnNotFiltered = Install(); } // Remove this filter when the object goes out of scope. + // + // The dtor also checks if we actually filtered the message and logs a + // trace message with the "gtklog" mask if we didn't: this allows checking + // if the filter is actually being used. ~LogFilterByMessage(); protected: @@ -118,6 +123,8 @@ protected: private: const char* const m_message; + mutable bool m_warnNotFiltered; + wxDECLARE_NO_COPY_CLASS(LogFilterByMessage); }; diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 288ae1373b..4e8bd2926c 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -203,14 +203,14 @@ LogFilter::wx_log_writer(GLogLevelFlags log_level, return g_log_writer_default(log_level, fields, n_fields, NULL); } -void LogFilter::Install() +bool LogFilter::Install() { if ( !ms_installed ) { if ( glib_check_version(2, 50, 0) != 0 ) { // No runtime support for log callback, we can't do anything. - return; + return false; } g_log_set_writer_func(LogFilter::wx_log_writer, NULL, NULL); @@ -220,6 +220,8 @@ void LogFilter::Install() // Put this object in front of the linked list. m_next = ms_first; ms_first = this; + + return true; } void LogFilter::Uninstall() @@ -248,6 +250,7 @@ bool LogFilterByMessage::Filter(GLogLevelFlags WXUNUSED(log_level), if ( strcmp(static_cast(f.value), m_message) == 0 ) { // This is the message we want to filter. + m_warnNotFiltered = false; return true; } } @@ -259,6 +262,11 @@ bool LogFilterByMessage::Filter(GLogLevelFlags WXUNUSED(log_level), LogFilterByMessage::~LogFilterByMessage() { Uninstall(); + + if ( m_warnNotFiltered ) + { + wxLogTrace("gtklog", "Message \"%s\" wasn't logged.", m_message); + } } } // namespace wxGTKImpl