Add categorized logging to MessageEventModel

This commit is contained in:
Tobias Fella
2023-05-06 17:53:01 +02:00
parent a89e04b92f
commit 4a29e0d0e1
3 changed files with 13 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMAddAppIcon) include(ECMAddAppIcon)
include(KDEGitCommitHooks) include(KDEGitCommitHooks)
include(ECMCheckOutboundLicense) include(ECMCheckOutboundLicense)
include(ECMQtDeclareLoggingCategory)
if (NOT ANDROID) if (NOT ANDROID)
include(KDEClangFormat) include(KDEClangFormat)
endif() endif()

View File

@@ -54,6 +54,13 @@ add_library(neochat STATIC
events/stickerevent.cpp events/stickerevent.cpp
) )
ecm_qt_declare_logging_category(neochat
HEADER "messageeventmodel_logging.h"
IDENTIFIER "MessageEvent"
CATEGORY_NAME "org.kde.neochat.messageeventmodel"
DEFAULT_SEVERITY Info
)
add_executable(neochat-app add_executable(neochat-app
main.cpp main.cpp
res.qrc res.qrc

View File

@@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only // SPDX-License-Identifier: GPL-3.0-only
#include "messageeventmodel.h" #include "messageeventmodel.h"
#include "messageeventmodel_logging.h"
#include "neochatconfig.h" #include "neochatconfig.h"
#include <connection.h> #include <connection.h>
@@ -242,7 +243,7 @@ void MessageEventModel::setRoom(NeoChatRoom *room)
beginResetModel(); beginResetModel();
endResetModel(); endResetModel();
}); });
qDebug() << "Connected to room" << room->id() << "as" << room->localUser()->id(); qCDebug(MessageEvent) << "Connected to room" << room->id() << "as" << room->localUser()->id();
} else { } else {
lastReadEventId.clear(); lastReadEventId.clear();
} }
@@ -357,7 +358,7 @@ QDateTime MessageEventModel::makeMessageTimestamp(const Quotient::Room::rev_iter
}; };
// What kind of room is that?.. // What kind of room is that?..
qCritical() << "No valid timestamps in the room timeline!"; qCCritical(MessageEvent) << "No valid timestamps in the room timeline!";
return {}; return {};
} }
@@ -459,6 +460,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
const auto row = idx.row(); const auto row = idx.row();
if (!m_currentRoom || row < 0 || row >= int(m_currentRoom->pendingEvents().size()) + m_currentRoom->timelineSize()) { if (!m_currentRoom || row < 0 || row >= int(m_currentRoom->pendingEvents().size()) + m_currentRoom->timelineSize()) {
qCWarning(MessageEvent) << "Accessing index out of bounds";
return {}; return {};
}; };
@@ -951,6 +953,7 @@ QVariant MessageEventModel::data(const QModelIndex &idx, int role) const
return row < static_cast<int>(m_currentRoom->pendingEvents().size()); return row < static_cast<int>(m_currentRoom->pendingEvents().size());
} }
qCWarning(MessageEvent) << "Unknown role" << role;
return {}; return {};
} }