mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 06:44:06 +02:00
add the VerboseLoggingHelper class for repeated messages
This commit is contained in:
parent
4e7e9641f0
commit
9c30903eb6
2 changed files with 70 additions and 0 deletions
34
libraries/shared/src/VerboseLoggingHelper.cpp
Normal file
34
libraries/shared/src/VerboseLoggingHelper.cpp
Normal file
|
@ -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 <qdebug.h>
|
||||
|
||||
#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<QString, int>::iterator message = _messageCountHash.begin();
|
||||
while (message != _messageCountHash.end()) {
|
||||
qDebug() << message.key().arg(message.value());
|
||||
message = _messageCountHash.erase(message);
|
||||
}
|
||||
}
|
36
libraries/shared/src/VerboseLoggingHelper.h
Normal file
36
libraries/shared/src/VerboseLoggingHelper.h
Normal file
|
@ -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 <qhash.h>
|
||||
#include <qobject.h>
|
||||
#include <qtimer.h>
|
||||
|
||||
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<QString, int> _messageCountHash;
|
||||
};
|
||||
|
||||
#endif // hifi_VerboseLoggingHelper_h
|
Loading…
Reference in a new issue