mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 06:57:37 +02:00
Skip duplicated log entries
This helps with log flooding. Successive repeated log messages will be skipped and counted, the count will be output when a different message is logged. A new option of 'keep_repeats' has been added to VIRCADIA_LOG_OPTIONS to disable this.
This commit is contained in:
parent
165537a4eb
commit
aab5b22e25
2 changed files with 19 additions and 1 deletions
|
@ -64,6 +64,8 @@ LogHandler::LogHandler() {
|
||||||
_shouldOutputThreadID = true;
|
_shouldOutputThreadID = true;
|
||||||
} else if (option == "milliseconds") {
|
} else if (option == "milliseconds") {
|
||||||
_shouldDisplayMilliseconds = true;
|
_shouldDisplayMilliseconds = true;
|
||||||
|
} else if (option == "keep_repeats") {
|
||||||
|
_keepRepeats = true;
|
||||||
} else if (option != "") {
|
} else if (option != "") {
|
||||||
fprintf(stdout, "Unrecognized option in VIRCADIA_LOG_OPTIONS: '%s'\n", option.toUtf8().constData());
|
fprintf(stdout, "Unrecognized option in VIRCADIA_LOG_OPTIONS: '%s'\n", option.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
@ -202,7 +204,18 @@ QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& cont
|
||||||
resetColor = colorReset();
|
resetColor = colorReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "%s%s%s", color, qPrintable(logMessage), resetColor);
|
if (_keepRepeats || _previousMessage != message) {
|
||||||
|
if (_repeatCount > 0) {
|
||||||
|
fprintf(stdout, "[Previous message was repeated %i times]\n", _repeatCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stdout, "%s%s%s", color, qPrintable(logMessage), resetColor);
|
||||||
|
_repeatCount = 0;
|
||||||
|
} else {
|
||||||
|
_repeatCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
_previousMessage = message;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
// On windows, this will output log lines into the Visual Studio "output" tab
|
// On windows, this will output log lines into the Visual Studio "output" tab
|
||||||
OutputDebugStringA(qPrintable(logMessage));
|
OutputDebugStringA(qPrintable(logMessage));
|
||||||
|
|
|
@ -67,6 +67,11 @@ private:
|
||||||
bool _shouldOutputThreadID { false };
|
bool _shouldOutputThreadID { false };
|
||||||
bool _shouldDisplayMilliseconds { false };
|
bool _shouldDisplayMilliseconds { false };
|
||||||
bool _useColor { false };
|
bool _useColor { false };
|
||||||
|
bool _keepRepeats { false };
|
||||||
|
|
||||||
|
QString _previousMessage;
|
||||||
|
int _repeatCount { 0 };
|
||||||
|
|
||||||
|
|
||||||
int _currentMessageID { 0 };
|
int _currentMessageID { 0 };
|
||||||
struct RepeatedMessageRecord {
|
struct RepeatedMessageRecord {
|
||||||
|
|
Loading…
Reference in a new issue