diff --git a/libraries/shared/src/VerboseLoggingHelper.cpp b/libraries/shared/src/VerboseLoggingHelper.cpp new file mode 100644 index 0000000000..6fa3f8a5a5 --- /dev/null +++ b/libraries/shared/src/VerboseLoggingHelper.cpp @@ -0,0 +1,34 @@ +// +// VerboseLoggingHelper.cpp +// libraries/shared/src +// +// Created by Stephen Birarda on 2014-10-28. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include "VerboseLoggingHelper.h" + +VerboseLoggingHelper& VerboseLoggingHelper::getInstance() { + static VerboseLoggingHelper sharedInstance; + return sharedInstance; +} + +VerboseLoggingHelper::VerboseLoggingHelper() { + // setup our timer to flush the verbose logs every 5 seconds + _timer = new QTimer(this); + connect(_timer, &QTimer::timeout, this, &VerboseLoggingHelper::flushMessages); + _timer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000); +} + +void VerboseLoggingHelper::flushMessages() { + QHash::iterator message = _messageCountHash.begin(); + while (message != _messageCountHash.end()) { + qDebug() << message.key().arg(message.value()); + message = _messageCountHash.erase(message); + } +} \ No newline at end of file diff --git a/libraries/shared/src/VerboseLoggingHelper.h b/libraries/shared/src/VerboseLoggingHelper.h new file mode 100644 index 0000000000..368dfa51e6 --- /dev/null +++ b/libraries/shared/src/VerboseLoggingHelper.h @@ -0,0 +1,36 @@ +// +// VerboseLoggingHelper.h +// libraries/shared/src +// +// Created by Stephen Birarda on 2014-10-28. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_VerboseLoggingHelper_h +#define hifi_VerboseLoggingHelper_h + +#include +#include +#include + +const int VERBOSE_LOG_INTERVAL_SECONDS = 5; + +class VerboseLoggingHelper : public QObject { + Q_OBJECT +public: + static VerboseLoggingHelper& getInstance(); + + void addMessage(const QString& message) { _messageCountHash[message] += 1; } +private: + VerboseLoggingHelper(); + + void flushMessages(); + + QTimer* _timer; + QHash _messageCountHash; +}; + +#endif // hifi_VerboseLoggingHelper_h \ No newline at end of file