summaryrefslogtreecommitdiffstats
path: root/qdb
diff options
context:
space:
mode:
authorRainer Keller <Rainer.Keller@qt.io>2018-02-06 15:45:47 +0100
committerRainer Keller <Rainer.Keller@qt.io>2018-02-12 11:37:20 +0000
commit24ca9064399d94b23cb4c5dd44c0377ee9404e91 (patch)
tree8abbc66b348ff03a5f0dab8a425680f842ea1cda /qdb
parented41752642af8a698e293fbd8a81e54cd770c433 (diff)
Store log messages in a buffer
For later usage important log messages are stored in a buffer. A logging class will notify listeners about new messages in the buffer. Change-Id: If892c050ffe1e929d9ccf08880db26d98fdb4ed9 Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io> Reviewed-by: Samuli Piippo <samuli.piippo@qt.io>
Diffstat (limited to 'qdb')
-rw-r--r--qdb/server/logging.cpp33
-rw-r--r--qdb/server/logging.h21
2 files changed, 54 insertions, 0 deletions
diff --git a/qdb/server/logging.cpp b/qdb/server/logging.cpp
index b02b23d..6be719b 100644
--- a/qdb/server/logging.cpp
+++ b/qdb/server/logging.cpp
@@ -73,6 +73,10 @@ void hostServerMessageHandler(QtMsgType type, const QMessageLogContext &context,
const auto message = qFormatLogMessage(type, context, msg);
const auto fullMsg = QString{"%1 %2\n"}.arg(prefix).arg(message).toUtf8();
+
+ if (type == QtInfoMsg || type == QtWarningMsg || type == QtCriticalMsg || type == QtFatalMsg)
+ Logging::instance().emitNewMessage(type, message);
+
auto written = logFile.write(fullMsg);
if (written != fullMsg.size()) {
qInstallMessageHandler(nullptr);
@@ -107,4 +111,33 @@ void setupLogging()
qWarning() << "Could not find writable application data location, logging to console";
}
}
+
+ Logging::instance();
+}
+
+void Logging::clearMessages()
+{
+ m_messages.clear();
+}
+
+const QContiguousCache<QPair<int, QString>> &Logging::getMessages()
+{
+ return m_messages;
+}
+
+Logging::Logging()
+{
+ m_messages.setCapacity(200);
+}
+
+Logging &Logging::instance()
+{
+ static Logging logging;
+ return logging;
+}
+
+void Logging::emitNewMessage(QtMsgType type, const QString &message)
+{
+ m_messages.append(qMakePair(type, message));
+ emit newMessage(type, message);
}
diff --git a/qdb/server/logging.h b/qdb/server/logging.h
index bf80196..c82c00c 100644
--- a/qdb/server/logging.h
+++ b/qdb/server/logging.h
@@ -29,6 +29,27 @@
#ifndef QDB_LOGGING_H
#define QDB_LOGGING_H
+#include <QObject>
+#include <QContiguousCache>
+#include <QPair>
+
void setupLogging();
+class Logging : public QObject
+{
+Q_OBJECT
+public:
+ void clearMessages();
+ const QContiguousCache<QPair<int, QString>> &getMessages();
+ static Logging &instance();
+ void emitNewMessage(QtMsgType type, const QString &message);
+
+private:
+ Logging();
+ QContiguousCache<QPair<int, QString>> m_messages;
+
+signals:
+ void newMessage(QtMsgType type, const QString &);
+};
+
#endif // QDB_LOGGING_H