Logging: apply filter to glib messages
Traditionally, glib messages were caught via LogRedirect. Later, they got redirected by installing a handler. That change disabled the message filtering for known harmless error messages in LogRedirect, which caused messages from folks to show up in TestCmdline D-Bus tests randomly, depending on the timing. Reestablish the filtering by checking it in the glog callback. To minimize changes, keep the error registry in LogRedirect. It must be thread-safe now.
This commit is contained in:
parent
e86cb1cd71
commit
c667ff0eb9
3 changed files with 32 additions and 12 deletions
|
@ -534,8 +534,15 @@ bool LogRedirect::process(FDs &fds) throw()
|
|||
return data_read;
|
||||
}
|
||||
|
||||
void LogRedirect::addIgnoreError(const std::string &error)
|
||||
{
|
||||
RecMutex::Guard guard = Logger::lock();
|
||||
m_knownErrors.insert(error);
|
||||
}
|
||||
|
||||
bool LogRedirect::ignoreError(const std::string &text)
|
||||
{
|
||||
RecMutex::Guard guard = Logger::lock();
|
||||
BOOST_FOREACH(const std::string &entry, m_knownErrors) {
|
||||
if (text.find(entry) != text.npos) {
|
||||
return true;
|
||||
|
|
|
@ -99,7 +99,15 @@ class LogRedirect : public LoggerStdout
|
|||
};
|
||||
|
||||
/** ignore any error output containing "error" */
|
||||
static void addIgnoreError(const std::string &error) { m_knownErrors.insert(error); }
|
||||
static void addIgnoreError(const std::string &error);
|
||||
|
||||
/**
|
||||
* Messages containing text listed in
|
||||
* SYNCEVOLUTION_SUPPRESS_ERRORS env variable (new-line separated)
|
||||
* or registered via addIgnoreError() are not real errors and
|
||||
* should only be logged for developers.
|
||||
*/
|
||||
static bool ignoreError(const std::string &text);
|
||||
|
||||
private:
|
||||
FDs m_stdout, m_stderr;
|
||||
|
@ -122,13 +130,6 @@ class LogRedirect : public LoggerStdout
|
|||
bool process(FDs &fds) throw();
|
||||
static void abortHandler(int sig) throw();
|
||||
|
||||
/**
|
||||
* ignore error messages containing text listed in
|
||||
* SYNCEVOLUTION_SUPPRESS_ERRORS env variable (new-line
|
||||
* separated)
|
||||
*/
|
||||
bool ignoreError(const std::string &text);
|
||||
|
||||
void init();
|
||||
|
||||
public:
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include <syncevo/Logging.h>
|
||||
#include <syncevo/LogStdout.h>
|
||||
#include <syncevo/LogRedirect.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
|
@ -369,10 +370,21 @@ void Logger::glogFunc(const gchar *logDomain,
|
|||
const gchar *message,
|
||||
gpointer userData)
|
||||
{
|
||||
Logger::instance().message((logLevel & (G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL)) ? ERROR :
|
||||
(logLevel & G_LOG_LEVEL_WARNING) ? WARNING :
|
||||
(logLevel & (G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO)) ? SHOW :
|
||||
DEBUG,
|
||||
Level level =
|
||||
(logLevel & (G_LOG_LEVEL_ERROR|G_LOG_LEVEL_CRITICAL)) ? ERROR :
|
||||
(logLevel & G_LOG_LEVEL_WARNING) ? WARNING :
|
||||
(logLevel & (G_LOG_LEVEL_MESSAGE|G_LOG_LEVEL_INFO)) ? SHOW :
|
||||
DEBUG;
|
||||
|
||||
// Downgrade some know error messages as registered with
|
||||
// the LogRedirect helper class. That messages are registered
|
||||
// there is a historic artifact.
|
||||
if (level != DEBUG &&
|
||||
LogRedirect::ignoreError(message)) {
|
||||
level = DEBUG;
|
||||
}
|
||||
|
||||
Logger::instance().message(level,
|
||||
NULL,
|
||||
NULL,
|
||||
0,
|
||||
|
|
Loading…
Reference in a new issue