From 5c5c69fff30a46816eb85c6b553be2b94efac1fc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 20 Jan 2017 11:20:48 -0800 Subject: [PATCH] setup the repeated message flusher on LogHandler thread --- libraries/shared/src/LogHandler.cpp | 7 ++++++- libraries/shared/src/LogHandler.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/shared/src/LogHandler.cpp b/libraries/shared/src/LogHandler.cpp index 35a3361c38..8e2c372bb6 100644 --- a/libraries/shared/src/LogHandler.cpp +++ b/libraries/shared/src/LogHandler.cpp @@ -186,7 +186,7 @@ void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext& getInstance().printMessage((LogMsgType) type, context, message); } -const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) { +void LogHandler::setupRepeatedMessageFlusher() { static std::once_flag once; std::call_once(once, [&] { // setup our timer to flush the verbose logs every 5 seconds @@ -194,6 +194,11 @@ const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) { connect(logFlushTimer, &QTimer::timeout, this, &LogHandler::flushRepeatedMessages); logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000); }); +} + +const QString& LogHandler::addRepeatedMessageRegex(const QString& regexString) { + // make sure we setup the repeated message flusher, but do it on the LogHandler thread + QMetaObject::invokeMethod(this, "setupRepeatedMessageFlusher"); QMutexLocker lock(&_mutex); return *_repeatedMessageRegexes.insert(regexString); diff --git a/libraries/shared/src/LogHandler.h b/libraries/shared/src/LogHandler.h index f80fad4c6a..ea961a8d4c 100644 --- a/libraries/shared/src/LogHandler.h +++ b/libraries/shared/src/LogHandler.h @@ -53,6 +53,9 @@ public: const QString& addRepeatedMessageRegex(const QString& regexString); const QString& addOnlyOnceMessageRegex(const QString& regexString); +private slots: + void setupRepeatedMessageFlusher(); + private: LogHandler(); ~LogHandler();