diff options
Diffstat (limited to 'qdb')
-rw-r--r-- | qdb/server/logging.cpp | 33 | ||||
-rw-r--r-- | qdb/server/logging.h | 21 |
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 |