Kaffeine/telegram-qt

Use QLoggingCategory

Kaffeine opened this issue · 3 comments

Use QLoggingCategory

As far as I read QLoggingCategory is about different output categories for different stuff.
But which categories are needed?
Also are the #ifdefs needed in front of the debug outputs?

Hello, sorry for the long reply.
I suppose that we can do something like

diff --git a/TelegramQt/CTelegramDispatcher.cpp b/TelegramQt/CTelegramDispatcher.cpp
index 011a710..13876ef 100644
--- a/TelegramQt/CTelegramDispatcher.cpp
+++ b/TelegramQt/CTelegramDispatcher.cpp
@@ -31,13 +31,15 @@ using namespace TelegramUtils;
 #include <QTimer>
 
 #include <QCryptographicHash>
-#include <QDebug>
+#include <QLoggingCategory>
 #include <algorithm>
 
 #ifdef DEVELOPER_BUILD
 #include "TLTypesDebug.hpp"
 #endif
 
+Q_LOGGING_CATEGORY(categoryDispatcher, "telegram-qt.dispatcher", QtWarningMsg)
+
 static const QVector<Telegram::DcOption> s_builtInDcs = QVector<Telegram::DcOption>()
         << Telegram::DcOption(QLatin1String("149.154.175.50") , 443)
         << Telegram::DcOption(QLatin1String("149.154.167.51") , 443)
@@ -212,7 +214,7 @@ QVector<Telegram::Peer> CTelegramDispatcher::dialogs() const
 
 void CTelegramDispatcher::addContacts(const QStringList &phoneNumbers, bool replace)
 {
-    qDebug() << "addContacts" << maskPhoneNumberList(phoneNumbers);
+    qCDebug(categoryDispatcher) << "addContacts" << maskPhoneNumberList(phoneNumbers);
     if (activeConnection()) {
         TLVector<TLInputContact> contactsVector;
         for (int i = 0; i < phoneNumbers.count(); ++i) {

So: one category per class.
The ifdefs in front of the debug are used to change verbosity for developer build. The dev build turns on dump of read object in json-like format.

A developer build output lools like this:

void CTelegramConnection::processMessagesGetDialogs(RpcProcessingContext*) 
"MessagesDialogsSlice" processed as Dialogs
void CTelegramDispatcher::onMessagesDialogsReceived(
        const TLMessagesDialogs&, quint32, quint32,
        const TLInputPeer&, quint32) TLMessagesDialogs(MessagesDialogsSlice) {
    count: 125
    dialogs: QVector(TLDialog(DialogChannel) {
        peer: TLPeer(PeerChannel) {
            channelId: 12345654321
        }
        topMessage: 30000
        topImportantMessage: 30000
        readInboxMaxId: 29999
        unreadCount: 1
        unreadImportantCount: 1
        notifySettings: TLPeerNotifySettings(PeerNotifySettings) {
            muteUntil: 2147483647
            sound: default
            showPreviews: true
            eventsMask: 0
        }
        pts: 30000
    }, TLDialog(Dialog) {
...
    })
    messages: QVector(TLMessage(Message) {
        flags: 1
        id: 30000
        fromId: 78901234
        toId: TLPeer(PeerChat) {
            chatId: 12345654321
        }
        date: 1500883344
        message: 
        media: TLMessageMedia(MessageMediaPhoto) {
            photo: TLPhoto(Photo) {
                id: 5455454554545454545
                accessHash: 6677889900112233445
                date: 1500883333
                sizes: QVector(TLPhotoSize(PhotoCachedSize) {
                    type: s
                    location: TLFileLocation(FileLocation) {
                        dcId: 2
                        volumeId: 12341234
                        localId: 123123
                        secret: 12341234123412341234
                    }
                    w: 90
                    h: 90
..
void CTelegramDispatcher::onUsersReceived(const QVector<TLUser>&) 23
void CContactModel::addContact(quint32) 111222333
void CContactModel::addContact(quint32) 222333444

and a release debug build output for the same operation is

void CTelegramConnection::processMessagesGetDialogs(RpcProcessingContext*)
"MessagesDialogsSlice" processed as Dialogs
void CTelegramDispatcher::onMessagesDialogsReceived(
        const TLMessagesDialogs&, quint32, quint32,
        const TLInputPeer&, quint32) 1910540000 0 0 0 0 30
void CTelegramDispatcher::onUsersReceived(const QVector<TLUser>&) 23
void CContactModel::addContact(quint32) 111222333
void CContactModel::addContact(quint32) 222333444

May be the ifdefs will be replaced in some far future, but I have no better solution yet.