mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 08:53:07 +02:00
complete output of suppressed repeated messages to log
This commit is contained in:
parent
8e3102266a
commit
424793b905
4 changed files with 24 additions and 7 deletions
|
@ -116,7 +116,7 @@ const QString SKIP_FILENAME = QStandardPaths::writableLocation(QStandardPaths::D
|
||||||
const QString DEFAULT_SCRIPTS_JS_URL = "http://public.highfidelity.io/scripts/defaultScripts.js";
|
const QString DEFAULT_SCRIPTS_JS_URL = "http://public.highfidelity.io/scripts/defaultScripts.js";
|
||||||
|
|
||||||
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
QString logMessage = LogHandler::getInstance().printMessage(type, context, message);
|
QString logMessage = LogHandler::getInstance().printMessage((LogMsgType) type, context, message);
|
||||||
|
|
||||||
if (!logMessage.isEmpty()) {
|
if (!logMessage.isEmpty()) {
|
||||||
Application::getInstance()->getLogger()->addMessage(qPrintable(logMessage));
|
Application::getInstance()->getLogger()->addMessage(qPrintable(logMessage));
|
||||||
|
|
|
@ -216,7 +216,7 @@ bool LimitedNodeList::packetVersionAndHashMatch(const QByteArray& packet) {
|
||||||
= LogHandler::getInstance().addRepeatedMessageRegex("Packet of type \\d+ received from unknown node with UUID");
|
= LogHandler::getInstance().addRepeatedMessageRegex("Packet of type \\d+ received from unknown node with UUID");
|
||||||
|
|
||||||
qDebug() << "Packet of type" << checkType << "received from unknown node with UUID"
|
qDebug() << "Packet of type" << checkType << "received from unknown node with UUID"
|
||||||
<< uuidStringWithoutCurlyBraces(uuidFromPacketHeader(packet));
|
<< qPrintable(uuidStringWithoutCurlyBraces(uuidFromPacketHeader(packet)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -36,7 +36,7 @@ LogHandler::LogHandler() :
|
||||||
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
logFlushTimer->start(VERBOSE_LOG_INTERVAL_SECONDS * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* stringForLogType(QtMsgType msgType) {
|
const char* stringForLogType(LogMsgType msgType) {
|
||||||
switch (msgType) {
|
switch (msgType) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
return "DEBUG";
|
return "DEBUG";
|
||||||
|
@ -46,6 +46,8 @@ const char* stringForLogType(QtMsgType msgType) {
|
||||||
return "FATAL";
|
return "FATAL";
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
return "WARNING";
|
return "WARNING";
|
||||||
|
case LogSuppressed:
|
||||||
|
return "SUPPRESS";
|
||||||
default:
|
default:
|
||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
@ -57,17 +59,24 @@ const char DATE_STRING_FORMAT[] = "%Y-%m-%d %H:%M:%S %z";
|
||||||
void LogHandler::flushRepeatedMessages() {
|
void LogHandler::flushRepeatedMessages() {
|
||||||
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
QHash<QString, int>::iterator message = _repeatMessageCountHash.begin();
|
||||||
while (message != _repeatMessageCountHash.end()) {
|
while (message != _repeatMessageCountHash.end()) {
|
||||||
|
QString repeatMessage = QString("%1 repeated log entries matching \"%2\" - Last entry: \"%3\"")
|
||||||
|
.arg(message.value()).arg(message.key()).arg(_lastRepeatedMessage.value(message.key()));
|
||||||
|
|
||||||
|
QMessageLogContext emptyContext;
|
||||||
|
printMessage(LogSuppressed, emptyContext, repeatMessage);
|
||||||
|
|
||||||
|
_lastRepeatedMessage.remove(message.key());
|
||||||
message = _repeatMessageCountHash.erase(message);
|
message = _repeatMessageCountHash.erase(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LogHandler::printMessage(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
QString LogHandler::printMessage(LogMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
|
|
||||||
if (message.isEmpty()) {
|
if (message.isEmpty()) {
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == QtDebugMsg) {
|
if (type == LogDebug) {
|
||||||
// for debug messages, check if this matches any of our regexes for repeated log messages
|
// for debug messages, check if this matches any of our regexes for repeated log messages
|
||||||
foreach(const QString& regexString, getInstance()._repeatedMessageRegexes) {
|
foreach(const QString& regexString, getInstance()._repeatedMessageRegexes) {
|
||||||
QRegExp repeatRegex(regexString);
|
QRegExp repeatRegex(regexString);
|
||||||
|
@ -118,5 +127,5 @@ QString LogHandler::printMessage(QtMsgType type, const QMessageLogContext& conte
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
void LogHandler::verboseMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) {
|
||||||
getInstance().printMessage(type, context, message);
|
getInstance().printMessage((LogMsgType) type, context, message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,14 @@
|
||||||
|
|
||||||
const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
|
const int VERBOSE_LOG_INTERVAL_SECONDS = 5;
|
||||||
|
|
||||||
|
enum LogMsgType {
|
||||||
|
LogDebug,
|
||||||
|
LogWarning,
|
||||||
|
LogCritical,
|
||||||
|
LogFatal,
|
||||||
|
LogSuppressed
|
||||||
|
};
|
||||||
|
|
||||||
/// Handles custom message handling and sending of stats/logs to Logstash instance
|
/// Handles custom message handling and sending of stats/logs to Logstash instance
|
||||||
class LogHandler : public QObject {
|
class LogHandler : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -33,7 +41,7 @@ public:
|
||||||
|
|
||||||
void setShouldOutputPID(bool shouldOutputPID) { _shouldOutputPID = shouldOutputPID; }
|
void setShouldOutputPID(bool shouldOutputPID) { _shouldOutputPID = shouldOutputPID; }
|
||||||
|
|
||||||
QString printMessage(QtMsgType type, const QMessageLogContext& context, const QString &message);
|
QString printMessage(LogMsgType type, const QMessageLogContext& context, const QString &message);
|
||||||
|
|
||||||
/// a qtMessageHandler that can be hooked up to a target that links to Qt
|
/// a qtMessageHandler that can be hooked up to a target that links to Qt
|
||||||
/// prints various process, message type, and time information
|
/// prints various process, message type, and time information
|
||||||
|
|
Loading…
Reference in a new issue