From aa24502129c7658bfbba95ca91c8626c0b485162 Mon Sep 17 00:00:00 2001 From: BruebachL <44814898+BruebachL@users.noreply.github.com> Date: Sun, 19 Jan 2025 14:14:23 +0100 Subject: [PATCH] Move logging from QDebug to QCDebug and introduce LoggingCategories. (#5491) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Move logging from QDebug to QCDebug and introduce LoggingCategories. * Lint. * Unlint like one change. * Remove .debug category since this is autofilled by Qt and used to differentiate between QCDebug and QCWarning and QCError. * Uncomment defaults, include main category. * Make PictureLoader logging a bit more useful. * Lint...? * Address comments. * Clean up some unnecessary classes in logging statements. * Add a new message format to the logging handler. * Lint. * Lint. * Support Windows in Regex --------- Co-authored-by: Lukas BrĂ¼bach Co-authored-by: ZeldaZach --- cockatrice/resources/config/qtlogging.ini | 48 +++++++++++++- .../src/client/network/release_channel.cpp | 28 ++++---- .../src/client/network/release_channel.h | 3 + .../network/spoiler_background_updater.cpp | 30 ++++----- .../network/spoiler_background_updater.h | 3 + cockatrice/src/client/sound_engine.cpp | 8 +-- cockatrice/src/client/sound_engine.h | 3 + .../src/client/tabs/tab_deck_editor.cpp | 2 - cockatrice/src/client/tabs/tab_game.cpp | 2 +- cockatrice/src/client/tabs/tab_game.h | 3 + cockatrice/src/client/tabs/tab_message.cpp | 2 +- cockatrice/src/client/tabs/tab_message.h | 4 ++ cockatrice/src/client/tabs/tab_supervisor.cpp | 6 +- cockatrice/src/client/tabs/tab_supervisor.h | 3 + .../src/client/tapped_out_interface.cpp | 6 +- cockatrice/src/client/tapped_out_interface.h | 3 + .../ui/picture_loader/picture_loader.cpp | 8 +-- .../client/ui/picture_loader/picture_loader.h | 5 ++ .../picture_loader/picture_loader_worker.cpp | 65 +++++++++---------- .../ui/picture_loader/picture_loader_worker.h | 3 + .../ui/picture_loader/picture_to_load.cpp | 3 - .../ui/picture_loader/picture_to_load.h | 4 ++ cockatrice/src/client/ui/theme_manager.cpp | 4 +- cockatrice/src/client/ui/theme_manager.h | 3 + cockatrice/src/client/ui/window_main.cpp | 16 +++-- cockatrice/src/client/ui/window_main.h | 7 ++ cockatrice/src/dialogs/dlg_edit_avatar.cpp | 2 +- cockatrice/src/dialogs/dlg_edit_avatar.h | 3 + cockatrice/src/dialogs/dlg_settings.cpp | 5 +- cockatrice/src/dialogs/dlg_settings.h | 3 + cockatrice/src/dialogs/dlg_tip_of_the_day.cpp | 2 +- cockatrice/src/dialogs/dlg_tip_of_the_day.h | 3 + cockatrice/src/dialogs/dlg_update.cpp | 2 +- cockatrice/src/dialogs/dlg_update.h | 4 ++ cockatrice/src/game/board/arrow_item.cpp | 2 - cockatrice/src/game/cards/card_database.cpp | 22 +++---- cockatrice/src/game/cards/card_database.h | 5 ++ .../card_database_parser/cockatrice_xml_3.cpp | 19 +++--- .../card_database_parser/cockatrice_xml_3.h | 3 + .../card_database_parser/cockatrice_xml_4.cpp | 20 +++--- .../card_database_parser/cockatrice_xml_4.h | 3 + cockatrice/src/game/cards/card_list.cpp | 2 +- cockatrice/src/game/cards/card_list.h | 3 + cockatrice/src/game/filters/filter_string.cpp | 2 +- cockatrice/src/game/filters/filter_string.h | 3 + cockatrice/src/game/game_scene.cpp | 4 +- cockatrice/src/game/game_scene.h | 4 ++ cockatrice/src/game/player/player.cpp | 2 +- cockatrice/src/game/player/player.h | 3 + cockatrice/src/game/zones/card_zone.cpp | 8 +-- cockatrice/src/game/zones/card_zone.h | 3 + cockatrice/src/game/zones/view_zone.cpp | 2 +- cockatrice/src/game/zones/view_zone.h | 3 + cockatrice/src/main.cpp | 37 ++++++++--- cockatrice/src/main.h | 5 ++ .../src/server/user/user_info_connection.cpp | 2 +- .../src/server/user/user_info_connection.h | 3 + cockatrice/src/settings/cache_settings.cpp | 4 +- cockatrice/src/settings/cache_settings.h | 3 + cockatrice/src/settings/servers_settings.cpp | 4 +- cockatrice/src/settings/servers_settings.h | 3 + .../src/settings/shortcuts_settings.cpp | 5 +- cockatrice/src/settings/shortcuts_settings.h | 3 + 63 files changed, 316 insertions(+), 162 deletions(-) diff --git a/cockatrice/resources/config/qtlogging.ini b/cockatrice/resources/config/qtlogging.ini index d51809d58..ddfbec51b 100644 --- a/cockatrice/resources/config/qtlogging.ini +++ b/cockatrice/resources/config/qtlogging.ini @@ -1,3 +1,47 @@ [Rules] -picture_loader.debug = true -deck_loader.debug = true \ No newline at end of file +# Uncomment a rule to disable logging for that category + +# main = false +# qt_translator = false +# window_main.* = false +# release_channel = false +# spoiler_background_updater = false +# theme_manager = false +# sound_engine = false +# tapped_out_interface = false + +# tab_game = false +# tab_message = false +# tab_supervisor = false + +# dlg_edit_avatar = false +# dlg_settings = false +# dlg_tip_of_the_day = false +# dlg_update = false + +# settings_cache = false +# servers_settings = false +# shortcuts_settings = false + +# player = false +# game_scene = false +# game_scene.player_addition_removal = false +# card_zone = false +# view_zone = false + +# user_info_connection = false + +# picture_loader = false +# picture_loader.worker = false +# picture_loader.card_back_cache_fail = false +# picture_loader.picture_to_load = false +# deck_loader = false +# card_database = false +# card_database.loading = false +# card_database.loading.success_or_failure = false +# cockatrice_xml.* = false +# cockatrice_xml.xml_3_parser = false +# cockatrice_xml.xml_4_parser = false +# card_list = false + +# filter_string = false \ No newline at end of file diff --git a/cockatrice/src/client/network/release_channel.cpp b/cockatrice/src/client/network/release_channel.cpp index d51261bde..b5040eeb0 100644 --- a/cockatrice/src/client/network/release_channel.cpp +++ b/cockatrice/src/client/network/release_channel.cpp @@ -33,7 +33,7 @@ ReleaseChannel::~ReleaseChannel() void ReleaseChannel::checkForUpdates() { QString releaseChannelUrl = getReleaseChannelUrl(); - qDebug() << "Searching for updates on the channel: " << releaseChannelUrl; + qCDebug(ReleaseChannelLog) << "Searching for updates on the channel: " << releaseChannelUrl; response = netMan->get(QNetworkRequest(releaseChannelUrl)); connect(response, &QNetworkReply::finished, this, &ReleaseChannel::releaseListFinished); } @@ -145,15 +145,15 @@ void StableReleaseChannel::releaseListFinished() QString shortHash = lastRelease->getCommitHash().left(GIT_SHORT_HASH_LEN); QString myHash = QString(VERSION_COMMIT); - qDebug() << "Current hash=" << myHash << "update hash=" << shortHash; + qCDebug(ReleaseChannelLog) << "Current hash=" << myHash << "update hash=" << shortHash; - qDebug() << "Got reply from release server, name=" << lastRelease->getName() - << "desc=" << lastRelease->getDescriptionUrl() << "date=" << lastRelease->getPublishDate() - << "url=" << lastRelease->getDownloadUrl(); + qCDebug(ReleaseChannelLog) << "Got reply from release server, name=" << lastRelease->getName() + << "desc=" << lastRelease->getDescriptionUrl() + << "date=" << lastRelease->getPublishDate() << "url=" << lastRelease->getDownloadUrl(); const QString &tagName = resultMap["tag_name"].toString(); QString url = QString(STABLETAG_URL) + tagName; - qDebug() << "Searching for commit hash corresponding to stable channel tag: " << tagName; + qCDebug(ReleaseChannelLog) << "Searching for commit hash corresponding to stable channel tag: " << tagName; response = netMan->get(QNetworkRequest(url)); connect(response, &QNetworkReply::finished, this, &StableReleaseChannel::tagListFinished); } @@ -178,11 +178,11 @@ void StableReleaseChannel::tagListFinished() } lastRelease->setCommitHash(resultMap["object"].toMap()["sha"].toString()); - qDebug() << "Got reply from tag server, commit=" << lastRelease->getCommitHash(); + qCDebug(ReleaseChannelLog) << "Got reply from tag server, commit=" << lastRelease->getCommitHash(); QString shortHash = lastRelease->getCommitHash().left(GIT_SHORT_HASH_LEN); QString myHash = QString(VERSION_COMMIT); - qDebug() << "Current hash=" << myHash << "update hash=" << shortHash; + qCDebug(ReleaseChannelLog) << "Current hash=" << myHash << "update hash=" << shortHash; const bool needToUpdate = (QString::compare(shortHash, myHash, Qt::CaseInsensitive) != 0); emit finishedCheck(needToUpdate, lastRelease->isCompatibleVersionFound(), lastRelease); @@ -249,13 +249,13 @@ void BetaReleaseChannel::releaseListFinished() lastRelease->setName(QString("%1 (%2)").arg(resultMap["tag_name"].toString()).arg(shortHash)); lastRelease->setDescriptionUrl(QString(BETARELEASE_CHANGESURL).arg(VERSION_COMMIT, shortHash)); - qDebug() << "Got reply from release server, size=" << resultMap.size() << "name=" << lastRelease->getName() - << "desc=" << lastRelease->getDescriptionUrl() << "commit=" << lastRelease->getCommitHash() - << "date=" << lastRelease->getPublishDate(); + qCDebug(ReleaseChannelLog) << "Got reply from release server, size=" << resultMap.size() + << "name=" << lastRelease->getName() << "desc=" << lastRelease->getDescriptionUrl() + << "commit=" << lastRelease->getCommitHash() << "date=" << lastRelease->getPublishDate(); QString betaBuildDownloadUrl = resultMap["assets_url"].toString(); - qDebug() << "Searching for a corresponding file on the beta channel: " << betaBuildDownloadUrl; + qCDebug(ReleaseChannelLog) << "Searching for a corresponding file on the beta channel: " << betaBuildDownloadUrl; response = netMan->get(QNetworkRequest(betaBuildDownloadUrl)); connect(response, &QNetworkReply::finished, this, &BetaReleaseChannel::fileListFinished); } @@ -275,7 +275,7 @@ void BetaReleaseChannel::fileListFinished() QVariantList resultList = jsonResponse.toVariant().toList(); QString shortHash = lastRelease->getCommitHash().left(GIT_SHORT_HASH_LEN); QString myHash = QString(VERSION_COMMIT); - qDebug() << "Current hash=" << myHash << "update hash=" << shortHash; + qCDebug(ReleaseChannelLog) << "Current hash=" << myHash << "update hash=" << shortHash; bool needToUpdate = (QString::compare(shortHash, myHash, Qt::CaseInsensitive) != 0); bool compatibleVersion = false; @@ -292,7 +292,7 @@ void BetaReleaseChannel::fileListFinished() if (downloadMatchesCurrentOS(*url)) { compatibleVersion = true; lastRelease->setDownloadUrl(*url); - qDebug() << "Found compatible version url=" << *url; + qCDebug(ReleaseChannelLog) << "Found compatible version url=" << *url; break; } } diff --git a/cockatrice/src/client/network/release_channel.h b/cockatrice/src/client/network/release_channel.h index 359bf2310..0fb459969 100644 --- a/cockatrice/src/client/network/release_channel.h +++ b/cockatrice/src/client/network/release_channel.h @@ -2,11 +2,14 @@ #define RELEASECHANNEL_H #include +#include #include #include #include #include +inline Q_LOGGING_CATEGORY(ReleaseChannelLog, "release_channel"); + class QNetworkReply; class QNetworkAccessManager; diff --git a/cockatrice/src/client/network/spoiler_background_updater.cpp b/cockatrice/src/client/network/spoiler_background_updater.cpp index fa767e738..ee1290a55 100644 --- a/cockatrice/src/client/network/spoiler_background_updater.cpp +++ b/cockatrice/src/client/network/spoiler_background_updater.cpp @@ -28,7 +28,7 @@ SpoilerBackgroundUpdater::SpoilerBackgroundUpdater(QObject *apParent) : QObject( // File exists means we're in spoiler season startSpoilerDownloadProcess(SPOILERS_STATUS_URL, false); } else { - qDebug() << "Spoilers Disabled"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoilers Disabled"; } } @@ -67,7 +67,7 @@ void SpoilerBackgroundUpdater::actDownloadFinishedSpoilersFile() reply->deleteLater(); emit spoilerCheckerDone(); } else { - qDebug() << "Error downloading spoilers file" << errorCode; + qCDebug(SpoilerBackgroundUpdaterLog) << "Error downloading spoilers file" << errorCode; emit spoilerCheckerDone(); } } @@ -81,11 +81,11 @@ bool SpoilerBackgroundUpdater::deleteSpoilerFile() // Delete the spoiler.xml file if (file.exists() && file.remove()) { - qDebug() << "Deleting spoiler.xml"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Deleting spoiler.xml"; return true; } - qDebug() << "Error: Spoiler.xml not found or not deleted"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Error: Spoiler.xml not found or not deleted"; return false; } @@ -101,24 +101,24 @@ void SpoilerBackgroundUpdater::actCheckIfSpoilerSeasonEnabled() trayIcon->showMessage(tr("Spoilers season has ended"), tr("Deleting spoiler.xml. Please run Oracle")); } - qDebug() << "Spoiler Season Offline"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler Season Offline"; emit spoilerCheckerDone(); } else if (errorCode == QNetworkReply::NoError) { - qDebug() << "Spoiler Service Online"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler Service Online"; startSpoilerDownloadProcess(SPOILERS_URL, true); } else if (errorCode == QNetworkReply::HostNotFoundError) { if (trayIcon) { trayIcon->showMessage(tr("Spoilers download failed"), tr("No internet connection")); } - qDebug() << "Spoiler download failed due to no internet connection"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler download failed due to no internet connection"; emit spoilerCheckerDone(); } else { if (trayIcon) { trayIcon->showMessage(tr("Spoilers download failed"), tr("Error") + " " + (short)errorCode); } - qDebug() << "Spoiler download failed with reason" << errorCode; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler download failed with reason" << errorCode; emit spoilerCheckerDone(); } } @@ -139,19 +139,19 @@ bool SpoilerBackgroundUpdater::saveDownloadedFile(QByteArray data) trayIcon->showMessage(tr("Spoilers already up to date"), tr("No new spoilers added")); } - qDebug() << "Spoilers Up to Date"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoilers Up to Date"; return false; } QFile file(fileName); if (!file.open(QIODevice::WriteOnly)) { - qDebug() << "Spoiler Service Error: File open (w) failed for" << fileName; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler Service Error: File open (w) failed for" << fileName; file.close(); return false; } if (file.write(data) == -1) { - qDebug() << "Spoiler Service Error: File write (w) failed for" << fileName; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler Service Error: File write (w) failed for" << fileName; file.close(); return false; } @@ -159,7 +159,7 @@ bool SpoilerBackgroundUpdater::saveDownloadedFile(QByteArray data) file.close(); // Data written, so reload the card database - qDebug() << "Spoiler Service Data Written"; + qCDebug(SpoilerBackgroundUpdaterLog) << "Spoiler Service Data Written"; const auto reloadOk = QtConcurrent::run([] { CardDatabaseManager::getInstance()->loadCardDatabases(); }); // If the user has notifications enabled, let them know @@ -202,12 +202,12 @@ QByteArray SpoilerBackgroundUpdater::getHash(const QString fileName) QCryptographicHash hash(QCryptographicHash::Algorithm::Md5); hash.addData(bytes); - qDebug() << "File Hash =" << hash.result(); + qCDebug(SpoilerBackgroundUpdaterLog) << "File Hash =" << hash.result(); file.close(); return hash.result(); } else { - qDebug() << "getHash ReadOnly failed!"; + qCDebug(SpoilerBackgroundUpdaterLog) << "getHash ReadOnly failed!"; file.close(); return QByteArray(); } @@ -221,7 +221,7 @@ QByteArray SpoilerBackgroundUpdater::getHash(QByteArray data) QCryptographicHash hash(QCryptographicHash::Algorithm::Md5); hash.addData(bytes); - qDebug() << "Data Hash =" << hash.result(); + qCDebug(SpoilerBackgroundUpdaterLog) << "Data Hash =" << hash.result(); return hash.result(); } diff --git a/cockatrice/src/client/network/spoiler_background_updater.h b/cockatrice/src/client/network/spoiler_background_updater.h index 7d7a2892c..a29488bf2 100644 --- a/cockatrice/src/client/network/spoiler_background_updater.h +++ b/cockatrice/src/client/network/spoiler_background_updater.h @@ -2,9 +2,12 @@ #define COCKATRICE_SPOILER_DOWNLOADER_H #include +#include #include #include +inline Q_LOGGING_CATEGORY(SpoilerBackgroundUpdaterLog, "spoiler_background_updater"); + class SpoilerBackgroundUpdater : public QObject { Q_OBJECT diff --git a/cockatrice/src/client/sound_engine.cpp b/cockatrice/src/client/sound_engine.cpp index 700e717b3..0f6ca3c83 100644 --- a/cockatrice/src/client/sound_engine.cpp +++ b/cockatrice/src/client/sound_engine.cpp @@ -37,7 +37,7 @@ SoundEngine::~SoundEngine() void SoundEngine::soundEnabledChanged() { if (SettingsCache::instance().getSoundEnabled()) { - qDebug() << "SoundEngine: enabling sound with" << audioData.size() << "sounds"; + qCDebug(SoundEngineLog) << "SoundEngine: enabling sound with" << audioData.size() << "sounds"; if (!player) { player = new QMediaPlayer; #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) @@ -46,7 +46,7 @@ void SoundEngine::soundEnabledChanged() #endif } } else { - qDebug() << "SoundEngine: disabling sound"; + qCDebug(SoundEngineLog) << "SoundEngine: disabling sound"; if (player) { player->stop(); player->deleteLater(); @@ -90,7 +90,7 @@ void SoundEngine::ensureThemeDirectoryExists() { if (SettingsCache::instance().getSoundThemeName().isEmpty() || !getAvailableThemes().contains(SettingsCache::instance().getSoundThemeName())) { - qDebug() << "Sounds theme name not set, setting default value"; + qCDebug(SoundEngineLog) << "Sounds theme name not set, setting default value"; SettingsCache::instance().setSoundThemeName(DEFAULT_THEME_NAME); } } @@ -131,7 +131,7 @@ QStringMap &SoundEngine::getAvailableThemes() void SoundEngine::themeChangedSlot() { QString themeName = SettingsCache::instance().getSoundThemeName(); - qDebug() << "Sound theme changed:" << themeName; + qCDebug(SoundEngineLog) << "Sound theme changed:" << themeName; QDir dir = getAvailableThemes().value(themeName); diff --git a/cockatrice/src/client/sound_engine.h b/cockatrice/src/client/sound_engine.h index 7d99c00f4..851ca3928 100644 --- a/cockatrice/src/client/sound_engine.h +++ b/cockatrice/src/client/sound_engine.h @@ -2,11 +2,14 @@ #define SOUNDENGINE_H #include +#include #include #include #include #include +inline Q_LOGGING_CATEGORY(SoundEngineLog, "sound_engine"); + class QBuffer; typedef QMap QStringMap; diff --git a/cockatrice/src/client/tabs/tab_deck_editor.cpp b/cockatrice/src/client/tabs/tab_deck_editor.cpp index 8e76df87a..81169aed5 100644 --- a/cockatrice/src/client/tabs/tab_deck_editor.cpp +++ b/cockatrice/src/client/tabs/tab_deck_editor.cpp @@ -1578,12 +1578,10 @@ void TabDeckEditor::actDecrement() void TabDeckEditor::setDeck(DeckLoader *_deck) { - qDebug() << " ORIGINAL BANNER CARD " << _deck->getBannerCard().first; deckModel->setDeckList(_deck); nameEdit->setText(deckModel->getDeckList()->getName()); commentsEdit->setText(deckModel->getDeckList()->getComments()); - qDebug() << deckModel->getDeckList()->getBannerCard() << " was the banner card"; bannerCardComboBox->setCurrentText(deckModel->getDeckList()->getBannerCard().first); updateBannerCardComboBox(); updateHash(); diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 289e7ee2f..b79968a5c 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -760,7 +760,7 @@ void TabGame::processGameEventContainer(const GameEventContainer &cont, default: { Player *player = players.value(playerId, 0); if (!player) { - qDebug() << "unhandled game event: invalid player id"; + qCDebug(TabGameLog) << "unhandled game event: invalid player id"; break; } player->processGameEvent(eventType, event, context, options); diff --git a/cockatrice/src/client/tabs/tab_game.h b/cockatrice/src/client/tabs/tab_game.h index bd0baa3a7..984ed4b0d 100644 --- a/cockatrice/src/client/tabs/tab_game.h +++ b/cockatrice/src/client/tabs/tab_game.h @@ -9,8 +9,11 @@ #include "tab.h" #include +#include #include +inline Q_LOGGING_CATEGORY(TabGameLog, "tab_game"); + class UserListProxy; class DeckViewContainer; class AbstractClient; diff --git a/cockatrice/src/client/tabs/tab_message.cpp b/cockatrice/src/client/tabs/tab_message.cpp index 83901af9f..2901dc2e5 100644 --- a/cockatrice/src/client/tabs/tab_message.cpp +++ b/cockatrice/src/client/tabs/tab_message.cpp @@ -148,7 +148,7 @@ void TabMessage::showSystemPopup(const Event_UserMessage &event) event.message().c_str()); connect(trayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); } else { - qDebug() << "Error: trayIcon is NULL. TabMessage::showSystemPopup failed"; + qCDebug(TabMessageLog) << "Error: trayIcon is NULL. TabMessage::showSystemPopup failed"; } } diff --git a/cockatrice/src/client/tabs/tab_message.h b/cockatrice/src/client/tabs/tab_message.h index 12a4188a2..dd7424e5d 100644 --- a/cockatrice/src/client/tabs/tab_message.h +++ b/cockatrice/src/client/tabs/tab_message.h @@ -3,6 +3,10 @@ #include "tab.h" +#include + +inline Q_LOGGING_CATEGORY(TabMessageLog, "tab_message"); + class AbstractClient; class ChatView; class LineEditUnfocusable; diff --git a/cockatrice/src/client/tabs/tab_supervisor.cpp b/cockatrice/src/client/tabs/tab_supervisor.cpp index 89c8c5d2c..c71d37a46 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.cpp +++ b/cockatrice/src/client/tabs/tab_supervisor.cpp @@ -760,7 +760,7 @@ void TabSupervisor::processGameEventContainer(const GameEventContainer &cont) if (tab) tab->processGameEventContainer(cont, qobject_cast(sender()), {}); else - qDebug() << "gameEvent: invalid gameId"; + qCDebug(TabSupervisorLog) << "gameEvent: invalid gameId"; } void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event) @@ -787,9 +787,9 @@ void TabSupervisor::processUserMessageEvent(const Event_UserMessage &event) void TabSupervisor::actShowPopup(const QString &message) { - qDebug() << "ACT SHOW POPUP"; + qCDebug(TabSupervisorLog) << "ACT SHOW POPUP"; if (trayIcon && (QApplication::activeWindow() == nullptr || QApplication::focusWidget() == nullptr)) { - qDebug() << "LAUNCHING POPUP"; + qCDebug(TabSupervisorLog) << "LAUNCHING POPUP"; // disconnect(trayIcon, SIGNAL(messageClicked()), nullptr, nullptr); trayIcon->showMessage(message, tr("Click to view")); // connect(trayIcon, SIGNAL(messageClicked()), chatView, SLOT(actMessageClicked())); diff --git a/cockatrice/src/client/tabs/tab_supervisor.h b/cockatrice/src/client/tabs/tab_supervisor.h index ad463f3ba..3925807fb 100644 --- a/cockatrice/src/client/tabs/tab_supervisor.h +++ b/cockatrice/src/client/tabs/tab_supervisor.h @@ -7,10 +7,13 @@ #include #include +#include #include #include #include +inline Q_LOGGING_CATEGORY(TabSupervisorLog, "tab_supervisor"); + class UserListManager; class QMenu; class AbstractClient; diff --git a/cockatrice/src/client/tapped_out_interface.cpp b/cockatrice/src/client/tapped_out_interface.cpp index 46ea4bf74..490fbe1fe 100644 --- a/cockatrice/src/client/tapped_out_interface.cpp +++ b/cockatrice/src/client/tapped_out_interface.cpp @@ -33,7 +33,7 @@ void TappedOutInterface::queryFinished(QNetworkReply *reply) * can be extracted from the header. The http status is a 302 "redirect". */ QString deckUrl = reply->rawHeader("Location"); - qDebug() << "Tappedout: good reply, http status" << httpStatus << "location" << deckUrl; + qCDebug(TappedOutInterfaceLog) << "Tappedout: good reply, http status" << httpStatus << "location" << deckUrl; QDesktopServices::openUrl("https://tappedout.net" + deckUrl); } else { /* @@ -57,8 +57,8 @@ void TappedOutInterface::queryFinished(QNetworkReply *reply) } QString errorMessage = errorMessageList.join("\n"); - qDebug() << "Tappedout: bad reply, http status" << httpStatus << "size" << data.size() << "message" - << errorMessage; + qCDebug(TappedOutInterfaceLog) << "Tappedout: bad reply, http status" << httpStatus << "size" << data.size() + << "message" << errorMessage; QMessageBox::critical(nullptr, tr("Error"), errorMessage); } diff --git a/cockatrice/src/client/tapped_out_interface.h b/cockatrice/src/client/tapped_out_interface.h index 3fb5f4778..2135ff7d9 100644 --- a/cockatrice/src/client/tapped_out_interface.h +++ b/cockatrice/src/client/tapped_out_interface.h @@ -4,8 +4,11 @@ #include "../game/cards/card_database.h" #include "decklist.h" +#include #include +inline Q_LOGGING_CATEGORY(TappedOutInterfaceLog, "tapped_out_interface"); + class QByteArray; class QNetworkAccessManager; class QNetworkReply; diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader.cpp index b0deee5a6..7f6424510 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader.cpp @@ -15,11 +15,8 @@ #include #include #include -#include #include -Q_LOGGING_CATEGORY(PictureLoaderLog, "picture_loader") - // never cache more than 300 cards at once for a single deck #define CACHED_CARD_PER_DECK_MAX 300 @@ -52,7 +49,7 @@ void PictureLoader::getCardBackLoadingInProgressPixmap(QPixmap &pixmap, QSize si { QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height()); if (!QPixmapCache::find(backCacheKey, &pixmap)) { - qCDebug(PictureLoaderLog) << "PictureLoader: cache fail for" << backCacheKey; + qCDebug(PictureLoaderCardBackCacheFailLog) << "PictureLoader: cache fail for" << backCacheKey; pixmap = QPixmap("theme:cardback").scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); QPixmapCache::insert(backCacheKey, pixmap); } @@ -62,7 +59,7 @@ void PictureLoader::getCardBackLoadingFailedPixmap(QPixmap &pixmap, QSize size) { QString backCacheKey = "_trice_card_back_" + QString::number(size.width()) + QString::number(size.height()); if (!QPixmapCache::find(backCacheKey, &pixmap)) { - qCDebug(PictureLoaderLog) << "PictureLoader: cache fail for" << backCacheKey; + qCDebug(PictureLoaderCardBackCacheFailLog) << "PictureLoader: cache fail for" << backCacheKey; pixmap = QPixmap("theme:cardback").scaled(size, Qt::KeepAspectRatio, Qt::SmoothTransformation); QPixmapCache::insert(backCacheKey, pixmap); } @@ -92,6 +89,7 @@ void PictureLoader::getPixmap(QPixmap &pixmap, CardInfoPtr card, QSize size) } // add the card to the load queue + qCDebug(PictureLoaderLog) << "Enqueuing " << card->getName() << " for " << card->getPixmapCacheKey(); getInstance().worker->enqueueImageLoad(card); } diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader.h b/cockatrice/src/client/ui/picture_loader/picture_loader.h index 8c33b3280..8819bddac 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader.h @@ -4,6 +4,11 @@ #include "../../../game/cards/card_database.h" #include "picture_loader_worker.h" +#include + +inline Q_LOGGING_CATEGORY(PictureLoaderLog, "picture_loader"); +inline Q_LOGGING_CATEGORY(PictureLoaderCardBackCacheFailLog, "picture_loader.card_back_cache_fail"); + class PictureLoader : public QObject { Q_OBJECT diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp index 9cc543b7c..9d79d1a36 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp @@ -5,14 +5,11 @@ #include #include -#include #include #include #include #include -Q_LOGGING_CATEGORY(PictureLoaderWorkerLog, "picture_loader.worker"); - // Card back returned by gatherer when card is not found QStringList PictureLoaderWorker::md5Blacklist = QStringList() << "db0c48db407a907c16ade38de048a441"; @@ -84,7 +81,7 @@ void PictureLoaderWorker::processLoadQueue() QString correctedCardName = cardBeingLoaded.getCard()->getCorrectedName(); qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardName << " set: " << setName << "]: Trying to load picture"; + << "[card: " << cardName << " set: " << setName << "]: Trying to load picture"; if (CardDatabaseManager::getInstance()->isProviderIdForPreferredPrinting( cardName, cardBeingLoaded.getCard()->getPixmapCacheKey())) { @@ -93,8 +90,8 @@ void PictureLoaderWorker::processLoadQueue() } } - qCDebug(PictureLoaderWorkerLog).nospace() << "PictureLoader: [card: " << cardName << " set: " << setName - << "]: No custom picture, trying to download"; + qCDebug(PictureLoaderWorkerLog).nospace() + << "[card: " << cardName << " set: " << setName << "]: No custom picture, trying to download"; cardsToDownload.append(cardBeingLoaded); cardBeingLoaded.clear(); if (!downloadRunning) { @@ -137,21 +134,21 @@ bool PictureLoaderWorker::cardImageExistsOnDisk(QString &setName, QString &corre imgReader.setFileName(_picsPath); if (imgReader.read(&image)) { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << correctedCardname << " set: " << setName << "]: Picture found on disk."; + << "[card: " << correctedCardname << " set: " << setName << "]: Picture found on disk."; imageLoaded(cardBeingLoaded.getCard(), image); return true; } imgReader.setFileName(_picsPath + ".full"); if (imgReader.read(&image)) { - qCDebug(PictureLoaderWorkerLog).nospace() << "PictureLoader: [card: " << correctedCardname - << " set: " << setName << "]: Picture.full found on disk."; + qCDebug(PictureLoaderWorkerLog).nospace() + << "[card: " << correctedCardname << " set: " << setName << "]: Picture.full found on disk."; imageLoaded(cardBeingLoaded.getCard(), image); return true; } imgReader.setFileName(_picsPath + ".xlhq"); if (imgReader.read(&image)) { - qCDebug(PictureLoaderWorkerLog).nospace() << "PictureLoader: [card: " << correctedCardname - << " set: " << setName << "]: Picture.xlhq found on disk."; + qCDebug(PictureLoaderWorkerLog).nospace() + << "[card: " << correctedCardname << " set: " << setName << "]: Picture.xlhq found on disk."; imageLoaded(cardBeingLoaded.getCard(), image); return true; } @@ -179,10 +176,9 @@ void PictureLoaderWorker::startNextPicDownload() picDownloadFailed(); } else { QUrl url(picUrl); - qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName() - << " set: " << cardBeingDownloaded.getSetName() << "]: Trying to fetch picture from url " - << url.toDisplayString(); + qCDebug(PictureLoaderWorkerLog).nospace() << "[card: " << cardBeingDownloaded.getCard()->getCorrectedName() + << " set: " << cardBeingDownloaded.getSetName() + << "]: Trying to fetch picture from url " << url.toDisplayString(); makeRequest(url); } } @@ -199,7 +195,7 @@ void PictureLoaderWorker::picDownloadFailed() mutex.unlock(); } else { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName() + << "[card: " << cardBeingDownloaded.getCard()->getCorrectedName() << " set: " << cardBeingDownloaded.getSetName() << "]: Picture NOT found, " << (picDownload ? "download failed" : "downloads disabled") << ", no more url combinations to try: BAILING OUT"; @@ -221,7 +217,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url) QUrl cachedRedirect = getCachedRedirect(url); if (!cachedRedirect.isEmpty()) { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName() + << "[card: " << cardBeingDownloaded.getCard()->getCorrectedName() << " set: " << cardBeingDownloaded.getSetName() << "]: Using cached redirect for " << url.toDisplayString() << " to " << cachedRedirect.toDisplayString(); return makeRequest(cachedRedirect); // Use the cached redirect @@ -246,7 +242,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url) cacheRedirect(url, redirectUrl); qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getCorrectedName() + << "[card: " << cardBeingDownloaded.getCard()->getCorrectedName() << " set: " << cardBeingDownloaded.getSetName() << "]: Caching redirect from " << url.toDisplayString() << " to " << redirectUrl.toDisplayString(); } @@ -326,18 +322,18 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) if (reply->error()) { if (isFromCache) { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: Removing corrupted cache file for url " - << reply->url().toDisplayString() << " and retrying (" << reply->errorString() << ")"; + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() + << "]: Removing corrupted cache file for url " << reply->url().toDisplayString() << " and retrying (" + << reply->errorString() << ")"; networkManager->cache()->remove(reply->url()); makeRequest(reply->url()); } else { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: " << (picDownload ? "Download" : "Cache search") - << " failed for url " << reply->url().toDisplayString() << " (" << reply->errorString() << ")"; + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() + << "]: " << (picDownload ? "Download" : "Cache search") << " failed for url " + << reply->url().toDisplayString() << " (" << reply->errorString() << ")"; picDownloadFailed(); startNextPicDownload(); @@ -353,9 +349,9 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) statusCode == 308) { QUrl redirectUrl = reply->header(QNetworkRequest::LocationHeader).toUrl(); qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: following " - << (isFromCache ? "cached redirect" : "redirect") << " to " << redirectUrl.toDisplayString(); + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() + << "]: following " << (isFromCache ? "cached redirect" : "redirect") << " to " + << redirectUrl.toDisplayString(); makeRequest(redirectUrl); reply->deleteLater(); return; @@ -366,8 +362,7 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) if (imageIsBlackListed(picData)) { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() << "]: Picture found, but blacklisted, will consider it as not found"; picDownloadFailed(); @@ -402,18 +397,18 @@ void PictureLoaderWorker::picDownloadFinished(QNetworkReply *reply) logSuccessMessage = true; } else { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: Possible " << (isFromCache ? "cached" : "downloaded") - << " picture at " << reply->url().toDisplayString() << " could not be loaded: " << reply->errorString(); + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() + << "]: Possible " << (isFromCache ? "cached" : "downloaded") << " picture at " + << reply->url().toDisplayString() << " could not be loaded: " << reply->errorString(); picDownloadFailed(); } if (logSuccessMessage) { qCDebug(PictureLoaderWorkerLog).nospace() - << "PictureLoader: [card: " << cardBeingDownloaded.getCard()->getName() - << " set: " << cardBeingDownloaded.getSetName() << "]: Image successfully " - << (isFromCache ? "loaded from cached" : "downloaded from") << " url " << reply->url().toDisplayString(); + << "[card: " << cardBeingDownloaded.getCard()->getName() << " set: " << cardBeingDownloaded.getSetName() + << "]: Image successfully " << (isFromCache ? "loaded from cached" : "downloaded from") << " url " + << reply->url().toDisplayString(); } reply->deleteLater(); diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h index 4ffa04902..823bcd7ec 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.h @@ -4,6 +4,7 @@ #include "../../../game/cards/card_database.h" #include "picture_to_load.h" +#include #include #include #include @@ -14,6 +15,8 @@ #define REDIRECT_TIMESTAMP "timestamp" #define REDIRECT_CACHE_FILENAME "cache.ini" +inline Q_LOGGING_CATEGORY(PictureLoaderWorkerLog, "picture_loader.worker"); + class PictureLoaderWorker : public QObject { Q_OBJECT diff --git a/cockatrice/src/client/ui/picture_loader/picture_to_load.cpp b/cockatrice/src/client/ui/picture_loader/picture_to_load.cpp index ca7f6e087..9800d7cc5 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_to_load.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_to_load.cpp @@ -7,9 +7,6 @@ #include #include #include -#include - -Q_LOGGING_CATEGORY(PictureToLoadLog, "picture_loader.picture_to_load") PictureToLoad::PictureToLoad(CardInfoPtr _card) : card(std::move(_card)), urlTemplates(SettingsCache::instance().downloads().getAllURLs()) diff --git a/cockatrice/src/client/ui/picture_loader/picture_to_load.h b/cockatrice/src/client/ui/picture_loader/picture_to_load.h index 64b22521f..96a114cd4 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_to_load.h +++ b/cockatrice/src/client/ui/picture_loader/picture_to_load.h @@ -3,6 +3,10 @@ #include "../../../game/cards/card_database.h" +#include + +inline Q_LOGGING_CATEGORY(PictureToLoadLog, "picture_loader.picture_to_load"); + class PictureToLoad { private: diff --git a/cockatrice/src/client/ui/theme_manager.cpp b/cockatrice/src/client/ui/theme_manager.cpp index 249032dfa..4decf3f40 100644 --- a/cockatrice/src/client/ui/theme_manager.cpp +++ b/cockatrice/src/client/ui/theme_manager.cpp @@ -32,7 +32,7 @@ void ThemeManager::ensureThemeDirectoryExists() { if (SettingsCache::instance().getThemeName().isEmpty() || !getAvailableThemes().contains(SettingsCache::instance().getThemeName())) { - qDebug() << "Theme name not set, setting default value"; + qCDebug(ThemeManagerLog) << "Theme name not set, setting default value"; SettingsCache::instance().setThemeName(NONE_THEME_NAME); } } @@ -105,7 +105,7 @@ QBrush ThemeManager::loadExtraBrush(QString fileName, QBrush &fallbackBrush) void ThemeManager::themeChangedSlot() { QString themeName = SettingsCache::instance().getThemeName(); - qDebug() << "Theme changed:" << themeName; + qCDebug(ThemeManagerLog) << "Theme changed:" << themeName; QString dirPath = getAvailableThemes().value(themeName); QDir dir = dirPath; diff --git a/cockatrice/src/client/ui/theme_manager.h b/cockatrice/src/client/ui/theme_manager.h index 3ab518b92..2385f5c23 100644 --- a/cockatrice/src/client/ui/theme_manager.h +++ b/cockatrice/src/client/ui/theme_manager.h @@ -3,11 +3,14 @@ #include #include +#include #include #include #include #include +inline Q_LOGGING_CATEGORY(ThemeManagerLog, "theme_manager"); + typedef QMap QStringMap; typedef QMap QBrushMap; diff --git a/cockatrice/src/client/ui/window_main.cpp b/cockatrice/src/client/ui/window_main.cpp index ef4aaf3c9..167e93e23 100644 --- a/cockatrice/src/client/ui/window_main.cpp +++ b/cockatrice/src/client/ui/window_main.cpp @@ -904,27 +904,29 @@ void MainWindow::startupConfigCheck() if (SettingsCache::instance().getClientVersion() == CLIENT_INFO_NOT_SET) { // no config found, 99% new clean install - qDebug() << "Startup: old client version empty, assuming first start after clean install"; + qCDebug(WindowMainStartupVersionLog) + << "Startup: old client version empty, assuming first start after clean install"; alertForcedOracleRun(VERSION_STRING, false); SettingsCache::instance().downloads().resetToDefaultURLs(); // populate the download urls SettingsCache::instance().setClientVersion(VERSION_STRING); } else if (SettingsCache::instance().getClientVersion() != VERSION_STRING) { // config found, from another (presumably older) version - qDebug() << "Startup: old client version" << SettingsCache::instance().getClientVersion() - << "differs, assuming first start after update"; + qCDebug(WindowMainStartupVersionLog) + << "Startup: old client version" << SettingsCache::instance().getClientVersion() + << "differs, assuming first start after update"; if (SettingsCache::instance().getNotifyAboutNewVersion()) { alertForcedOracleRun(VERSION_STRING, true); } else { const auto reloadOk0 = QtConcurrent::run([] { CardDatabaseManager::getInstance()->loadCardDatabases(); }); } - qDebug() << "[MainWindow] Migrating shortcuts after update detected."; + qCDebug(WindowMainStartupShortcutsLog) << "[MainWindow] Migrating shortcuts after update detected."; SettingsCache::instance().shortcuts().migrateShortcuts(); SettingsCache::instance().setClientVersion(VERSION_STRING); } else { // previous config from this version found - qDebug() << "Startup: found config with current version"; + qCDebug(WindowMainStartupVersionLog) << "Startup: found config with current version"; const auto reloadOk1 = QtConcurrent::run([] { CardDatabaseManager::getInstance()->loadCardDatabases(); }); // Run the tips dialog only on subsequent startups. @@ -1036,11 +1038,11 @@ void MainWindow::changeEvent(QEvent *event) if (isActiveWindow() && !bHasActivated) { bHasActivated = true; if (!connectTo.isEmpty()) { - qDebug() << "Command line connect to " << connectTo; + qCDebug(WindowMainStartupAutoconnectLog) << "Command line connect to " << connectTo; client->connectToServer(connectTo.host(), connectTo.port(), connectTo.userName(), connectTo.password()); } else if (SettingsCache::instance().servers().getAutoConnect() && !SettingsCache::instance().debug().getLocalGameOnStartup()) { - qDebug() << "Attempting auto-connect..."; + qCDebug(WindowMainStartupAutoconnectLog) << "Attempting auto-connect..."; DlgConnect dlg(this); client->connectToServer(dlg.getHost(), static_cast(dlg.getPort()), dlg.getPlayerName(), dlg.getPassword()); diff --git a/cockatrice/src/client/ui/window_main.h b/cockatrice/src/client/ui/window_main.h index 73f6c30cd..8ba3ea440 100644 --- a/cockatrice/src/client/ui/window_main.h +++ b/cockatrice/src/client/ui/window_main.h @@ -24,12 +24,19 @@ #include "pb/response.pb.h" #include +#include #include #include #include #include #include +inline Q_LOGGING_CATEGORY(WindowMainLog, "window_main"); +inline Q_LOGGING_CATEGORY(WindowMainStartupLog, "window_main.startup"); +inline Q_LOGGING_CATEGORY(WindowMainStartupVersionLog, "window_main.startup.version"); +inline Q_LOGGING_CATEGORY(WindowMainStartupShortcutsLog, "window_main.startup.shortcuts"); +inline Q_LOGGING_CATEGORY(WindowMainStartupAutoconnectLog, "window_main.startup.autoconnect"); + class Release; class DlgConnect; class DlgViewLog; diff --git a/cockatrice/src/dialogs/dlg_edit_avatar.cpp b/cockatrice/src/dialogs/dlg_edit_avatar.cpp index da85da525..8a973df4e 100644 --- a/cockatrice/src/dialogs/dlg_edit_avatar.cpp +++ b/cockatrice/src/dialogs/dlg_edit_avatar.cpp @@ -61,7 +61,7 @@ void DlgEditAvatar::actBrowse() imgReader.setDecideFormatFromContent(true); imgReader.setFileName(fileName); if (!imgReader.read(&image)) { - qDebug() << "Avatar image loading failed for file:" << fileName; + qCDebug(DlgEditAvatarLog) << "Avatar image loading failed for file:" << fileName; imageLabel->setText(tr("Invalid image chosen.")); return; } diff --git a/cockatrice/src/dialogs/dlg_edit_avatar.h b/cockatrice/src/dialogs/dlg_edit_avatar.h index a3fb56f3d..604650fa2 100644 --- a/cockatrice/src/dialogs/dlg_edit_avatar.h +++ b/cockatrice/src/dialogs/dlg_edit_avatar.h @@ -4,6 +4,9 @@ #include #include #include +#include + +inline Q_LOGGING_CATEGORY(DlgEditAvatarLog, "dlg_edit_avatar"); class QLabel; class QPushButton; diff --git a/cockatrice/src/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index 9034097d7..861090e5c 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -198,7 +198,8 @@ QString GeneralSettingsPage::languageName(const QString &lang) QString appNameHint = translationPrefix + "_" + lang; bool appTranslationLoaded = qTranslator.load(appNameHint, translationPath); if (!appTranslationLoaded) { - qDebug() << "Unable to load" << translationPrefix << "translation" << appNameHint << "at" << translationPath; + qCDebug(DlgSettingsLog) << "Unable to load" << translationPrefix << "translation" << appNameHint << "at" + << translationPath; } return qTranslator.translate("i18n", DEFAULT_LANG_NAME); @@ -1535,7 +1536,7 @@ void DlgSettings::closeEvent(QCloseEvent *event) bool showLoadError = true; QString loadErrorMessage = tr("Unknown Error loading card database"); LoadStatus loadStatus = CardDatabaseManager::getInstance()->getLoadStatus(); - qDebug() << "Card Database load status: " << loadStatus; + qCDebug(DlgSettingsLog) << "Card Database load status: " << loadStatus; switch (loadStatus) { case Ok: showLoadError = false; diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index 4aefd1856..cc6120ffc 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -8,9 +8,12 @@ #include #include #include +#include #include #include +inline Q_LOGGING_CATEGORY(DlgSettingsLog, "dlg_settings"); + class ShortcutTreeView; class SearchLineEdit; class QTreeView; diff --git a/cockatrice/src/dialogs/dlg_tip_of_the_day.cpp b/cockatrice/src/dialogs/dlg_tip_of_the_day.cpp index c4b75ccd0..b782e4a19 100644 --- a/cockatrice/src/dialogs/dlg_tip_of_the_day.cpp +++ b/cockatrice/src/dialogs/dlg_tip_of_the_day.cpp @@ -146,7 +146,7 @@ void DlgTipOfTheDay::updateTip(int tipId) tipTextContent->setText(contentText); if (!image->load(imagePath)) { - qDebug() << "Image failed to load from" << imagePath; + qCDebug(DlgTipOfTheDayLog) << "Image failed to load from" << imagePath; imageLabel->clear(); } else { int h = std::min(std::max(imageLabel->height(), MIN_TIP_IMAGE_HEIGHT), MAX_TIP_IMAGE_HEIGHT); diff --git a/cockatrice/src/dialogs/dlg_tip_of_the_day.h b/cockatrice/src/dialogs/dlg_tip_of_the_day.h index 79d01f5c6..4a7d86354 100644 --- a/cockatrice/src/dialogs/dlg_tip_of_the_day.h +++ b/cockatrice/src/dialogs/dlg_tip_of_the_day.h @@ -6,9 +6,12 @@ #include #include #include +#include #include #include +inline Q_LOGGING_CATEGORY(DlgTipOfTheDayLog, "dlg_tip_of_the_day"); + class QLabel; class QPushButton; class QCheckBox; diff --git a/cockatrice/src/dialogs/dlg_update.cpp b/cockatrice/src/dialogs/dlg_update.cpp index 8ef8ea09b..ecea4854d 100644 --- a/cockatrice/src/dialogs/dlg_update.cpp +++ b/cockatrice/src/dialogs/dlg_update.cpp @@ -221,7 +221,7 @@ void DlgUpdate::downloadSuccessful(const QUrl &filepath) // Try to open the installer. If it opens, quit Cockatrice if (QDesktopServices::openUrl(filepath)) { QMetaObject::invokeMethod(static_cast(parent()), "close", Qt::QueuedConnection); - qDebug() << "Opened downloaded update file successfully - closing Cockatrice"; + qCDebug(DlgUpdateLog) << "Opened downloaded update file successfully - closing Cockatrice"; close(); } else { setLabel(tr("Error")); diff --git a/cockatrice/src/dialogs/dlg_update.h b/cockatrice/src/dialogs/dlg_update.h index 0eaa3ba76..e4415283e 100644 --- a/cockatrice/src/dialogs/dlg_update.h +++ b/cockatrice/src/dialogs/dlg_update.h @@ -4,8 +4,12 @@ #include "../client/update_downloader.h" #include +#include #include #include + +inline Q_LOGGING_CATEGORY(DlgUpdateLog, "dlg_update"); + class Release; class DlgUpdate : public QDialog diff --git a/cockatrice/src/game/board/arrow_item.cpp b/cockatrice/src/game/board/arrow_item.cpp index cfc140d58..512d1ab72 100644 --- a/cockatrice/src/game/board/arrow_item.cpp +++ b/cockatrice/src/game/board/arrow_item.cpp @@ -22,7 +22,6 @@ ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTar : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false), color(_color), fullColor(true) { - qDebug() << "ArrowItem constructor: startItem=" << static_cast(startItem); setZValue(2000000005); if (startItem) @@ -36,7 +35,6 @@ ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTar ArrowItem::~ArrowItem() { - qDebug() << "ArrowItem destructor"; } void ArrowItem::delArrow() diff --git a/cockatrice/src/game/cards/card_database.cpp b/cockatrice/src/game/cards/card_database.cpp index 21099c6ff..d1e9eea31 100644 --- a/cockatrice/src/game/cards/card_database.cpp +++ b/cockatrice/src/game/cards/card_database.cpp @@ -102,7 +102,7 @@ public: inline bool operator()(const CardSetPtr &a, const CardSetPtr &b) const { if (a.isNull() || b.isNull()) { - qDebug() << "SetList::KeyCompareFunctor a or b is null"; + qCDebug(CardDatabaseLog) << "SetList::KeyCompareFunctor a or b is null"; return false; } @@ -170,7 +170,7 @@ void SetList::enableAll() CardSetPtr set = at(i); if (set == nullptr) { - qDebug() << "enabledAll has null"; + qCDebug(CardDatabaseLog) << "enabledAll has null"; continue; } @@ -201,7 +201,7 @@ void SetList::guessSortKeys() for (int i = 0; i < size(); ++i) { CardSetPtr set = at(i); if (set.isNull()) { - qDebug() << "guessSortKeys set is null"; + qCDebug(CardDatabaseLog) << "guessSortKeys set is null"; continue; } set->setSortKey(i); @@ -415,7 +415,7 @@ void CardDatabase::clear() void CardDatabase::addCard(CardInfoPtr card) { if (card == nullptr) { - qDebug() << "addCard(nullptr)"; + qCDebug(CardDatabaseLog) << "CardDatabase::addCard(nullptr)"; return; } @@ -440,7 +440,7 @@ void CardDatabase::addCard(CardInfoPtr card) void CardDatabase::removeCard(CardInfoPtr card) { if (card.isNull()) { - qDebug() << "removeCard(nullptr)"; + qCDebug(CardDatabaseLog) << "CardDatabase::removeCard(nullptr)"; return; } @@ -582,8 +582,8 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path) } int msecs = startTime.msecsTo(QTime::currentTime()); - qDebug() << "[CardDatabase] loadCardDatabase(): Path =" << path << "Status =" << tempLoadStatus - << "Cards =" << cards.size() << "Sets =" << sets.size() << QString("%1ms").arg(msecs); + qCDebug(CardDatabaseLoadingLog) << "Path =" << path << "Status =" << tempLoadStatus << "Cards =" << cards.size() + << "Sets =" << sets.size() << QString("%1ms").arg(msecs); return tempLoadStatus; } @@ -592,7 +592,7 @@ LoadStatus CardDatabase::loadCardDatabases() { reloadDatabaseMutex->lock(); - qDebug() << "CardDatabase::loadCardDatabases start"; + qCDebug(CardDatabaseLoadingLog) << "Started"; clear(); // remove old db @@ -613,7 +613,7 @@ LoadStatus CardDatabase::loadCardDatabases() for (auto i = 0; i < databasePaths.size(); ++i) { const auto &databasePath = databasePaths.at(i); - qDebug() << "Loading Custom Set" << i << "(" << databasePath << ")"; + qCDebug(CardDatabaseLoadingLog) << "Loading Custom Set" << i << "(" << databasePath << ")"; loadCardDatabase(databasePath); } @@ -626,10 +626,10 @@ LoadStatus CardDatabase::loadCardDatabases() if (loadStatus == Ok) { checkUnknownSets(); // update deck editors, etc - qDebug() << "CardDatabase::loadCardDatabases success"; + qCDebug(CardDatabaseLoadingSuccessOrFailureLog) << "Success"; emit cardDatabaseLoadingFinished(); } else { - qDebug() << "CardDatabase::loadCardDatabases failed"; + qCDebug(CardDatabaseLoadingSuccessOrFailureLog) << "Failed"; emit cardDatabaseLoadingFailed(); // bring up the settings dialog } diff --git a/cockatrice/src/game/cards/card_database.h b/cockatrice/src/game/cards/card_database.h index a88f9671c..74918939a 100644 --- a/cockatrice/src/game/cards/card_database.h +++ b/cockatrice/src/game/cards/card_database.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,10 @@ #include #include +inline Q_LOGGING_CATEGORY(CardDatabaseLog, "card_database"); +inline Q_LOGGING_CATEGORY(CardDatabaseLoadingLog, "card_database.loading"); +inline Q_LOGGING_CATEGORY(CardDatabaseLoadingSuccessOrFailureLog, "card_database.loading.success_or_failure"); + class CardDatabase; class CardInfo; class CardInfoPerSet; diff --git a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.cpp b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.cpp index c27ce732d..403231886 100644 --- a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.cpp +++ b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.cpp @@ -13,10 +13,10 @@ bool CockatriceXml3Parser::getCanParseFile(const QString &fileName, QIODevice &device) { - qDebug() << "[CockatriceXml3Parser] Trying to parse: " << fileName; + qCDebug(CockatriceXml3Log) << "Trying to parse: " << fileName; if (!fileName.endsWith(".xml", Qt::CaseInsensitive)) { - qDebug() << "[CockatriceXml3Parser] Parsing failed: wrong extension"; + qCDebug(CockatriceXml3Log) << "Parsing failed: wrong extension"; return false; } @@ -28,12 +28,12 @@ bool CockatriceXml3Parser::getCanParseFile(const QString &fileName, QIODevice &d if (version == COCKATRICE_XML3_TAGVER) { return true; } else { - qDebug() << "[CockatriceXml3Parser] Parsing failed: wrong version" << version; + qCDebug(CockatriceXml3Log) << "Parsing failed: wrong version" << version; return false; } } else { - qDebug() << "[CockatriceXml3Parser] Parsing failed: wrong element tag" << xml.name(); + qCDebug(CockatriceXml3Log) << "Parsing failed: wrong element tag" << xml.name(); return false; } } @@ -58,7 +58,7 @@ void CockatriceXml3Parser::parseFile(QIODevice &device) } else if (name == "cards") { loadCardsFromXml(xml); } else if (!name.isEmpty()) { - qDebug() << "[CockatriceXml3Parser] Unknown item" << name << ", trying to continue anyway"; + qCDebug(CockatriceXml3Log) << "Unknown item" << name << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -93,7 +93,7 @@ void CockatriceXml3Parser::loadSetsFromXml(QXmlStreamReader &xml) releaseDate = QDate::fromString(xml.readElementText(QXmlStreamReader::IncludeChildElements), Qt::ISODate); } else if (!name.isEmpty()) { - qDebug() << "[CockatriceXml3Parser] Unknown set property" << name << ", trying to continue anyway"; + qCDebug(CockatriceXml3Log) << "Unknown set property" << name << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -263,8 +263,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml) relatedCards << relation; } } else if (!xmlName.isEmpty()) { - qDebug() << "[CockatriceXml3Parser] Unknown card property" << xmlName - << ", trying to continue anyway"; + qCDebug(CockatriceXml3Log) << "Unknown card property" << xmlName << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -281,7 +280,7 @@ void CockatriceXml3Parser::loadCardsFromXml(QXmlStreamReader &xml) static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSetPtr &set) { if (set.isNull()) { - qDebug() << "&operator<< set is nullptr"; + qCDebug(CockatriceXml3Log) << "&operator<< set is nullptr"; return xml; } @@ -298,7 +297,7 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSetPtr &set static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &info) { if (info.isNull()) { - qDebug() << "operator<< info is nullptr"; + qCDebug(CockatriceXml3Log) << "operator<< info is nullptr"; return xml; } diff --git a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.h b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.h index 9e7726e35..f8c060774 100644 --- a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.h +++ b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_3.h @@ -3,8 +3,11 @@ #include "card_database_parser.h" +#include #include +inline Q_LOGGING_CATEGORY(CockatriceXml3Log, "cockatrice_xml.xml_3_parser"); + class CockatriceXml3Parser : public ICardDatabaseParser { Q_OBJECT diff --git a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.cpp b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.cpp index 36a179345..e7f657b96 100644 --- a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.cpp +++ b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.cpp @@ -13,10 +13,10 @@ bool CockatriceXml4Parser::getCanParseFile(const QString &fileName, QIODevice &device) { - qDebug() << "[CockatriceXml4Parser] Trying to parse: " << fileName; + qCDebug(CockatriceXml4Log) << "Trying to parse: " << fileName; if (!fileName.endsWith(".xml", Qt::CaseInsensitive)) { - qDebug() << "[CockatriceXml4Parser] Parsing failed: wrong extension"; + qCDebug(CockatriceXml4Log) << "Parsing failed: wrong extension"; return false; } @@ -28,12 +28,12 @@ bool CockatriceXml4Parser::getCanParseFile(const QString &fileName, QIODevice &d if (version == COCKATRICE_XML4_TAGVER) { return true; } else { - qDebug() << "[CockatriceXml4Parser] Parsing failed: wrong version" << version; + qCDebug(CockatriceXml4Log) << "Parsing failed: wrong version" << version; return false; } } else { - qDebug() << "[CockatriceXml4Parser] Parsing failed: wrong element tag" << xml.name(); + qCDebug(CockatriceXml4Log) << "Parsing failed: wrong element tag" << xml.name(); return false; } } @@ -58,7 +58,7 @@ void CockatriceXml4Parser::parseFile(QIODevice &device) } else if (xmlName == "cards") { loadCardsFromXml(xml); } else if (!xmlName.isEmpty()) { - qDebug() << "[CockatriceXml4Parser] Unknown item" << xmlName << ", trying to continue anyway"; + qCDebug(CockatriceXml4Log) << "Unknown item" << xmlName << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -96,8 +96,7 @@ void CockatriceXml4Parser::loadSetsFromXml(QXmlStreamReader &xml) } else if (xmlName == "priority") { priority = xml.readElementText(QXmlStreamReader::IncludeChildElements).toShort(); } else if (!xmlName.isEmpty()) { - qDebug() << "[CockatriceXml4Parser] Unknown set property" << xmlName - << ", trying to continue anyway"; + qCDebug(CockatriceXml4Log) << "Unknown set property" << xmlName << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -230,8 +229,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml) relatedCards << relation; } } else if (!xmlName.isEmpty()) { - qDebug() << "[CockatriceXml4Parser] Unknown card property" << xmlName - << ", trying to continue anyway"; + qCDebug(CockatriceXml4Log) << "Unknown card property" << xmlName << ", trying to continue anyway"; xml.skipCurrentElement(); } } @@ -247,7 +245,7 @@ void CockatriceXml4Parser::loadCardsFromXml(QXmlStreamReader &xml) static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSetPtr &set) { if (set.isNull()) { - qDebug() << "&operator<< set is nullptr"; + qCDebug(CockatriceXml4Log) << "&operator<< set is nullptr"; return xml; } @@ -265,7 +263,7 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardSetPtr &set static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &info) { if (info.isNull()) { - qDebug() << "operator<< info is nullptr"; + qCDebug(CockatriceXml4Log) << "operator<< info is nullptr"; return xml; } diff --git a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.h b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.h index 82f71324a..9cd200441 100644 --- a/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.h +++ b/cockatrice/src/game/cards/card_database_parser/cockatrice_xml_4.h @@ -3,8 +3,11 @@ #include "card_database_parser.h" +#include #include +inline Q_LOGGING_CATEGORY(CockatriceXml4Log, "cockatrice_xml.xml_4_parser"); + class CockatriceXml4Parser : public ICardDatabaseParser { Q_OBJECT diff --git a/cockatrice/src/game/cards/card_list.cpp b/cockatrice/src/game/cards/card_list.cpp index 6261e5a9a..74961becc 100644 --- a/cockatrice/src/game/cards/card_list.cpp +++ b/cockatrice/src/game/cards/card_list.cpp @@ -151,6 +151,6 @@ std::function CardList::getExtractorFor(SortOption option) } // this line should never be reached - qDebug() << "cardlist.cpp: Could not find extractor for SortOption" << option; + qCDebug(CardListLog) << "cardlist.cpp: Could not find extractor for SortOption" << option; return [](CardItem *) { return ""; }; } \ No newline at end of file diff --git a/cockatrice/src/game/cards/card_list.h b/cockatrice/src/game/cards/card_list.h index 503cb6c17..1bbf08639 100644 --- a/cockatrice/src/game/cards/card_list.h +++ b/cockatrice/src/game/cards/card_list.h @@ -2,6 +2,9 @@ #define CARDLIST_H #include +#include + +inline Q_LOGGING_CATEGORY(CardListLog, "card_list"); class CardItem; diff --git a/cockatrice/src/game/filters/filter_string.cpp b/cockatrice/src/game/filters/filter_string.cpp index a02cda36d..d1defdefa 100644 --- a/cockatrice/src/game/filters/filter_string.cpp +++ b/cockatrice/src/game/filters/filter_string.cpp @@ -382,7 +382,7 @@ FilterString::FilterString(const QString &expr) }); if (!search.parse(ba.data(), result)) { - qDebug().nospace() << "FilterString error for " << expr << "; " << qPrintable(_error); + qCDebug(FilterStringLog).nospace() << "FilterString error for " << expr << "; " << qPrintable(_error); result = [](const CardData &) -> bool { return false; }; } } diff --git a/cockatrice/src/game/filters/filter_string.h b/cockatrice/src/game/filters/filter_string.h index aabeb015d..a633a235b 100644 --- a/cockatrice/src/game/filters/filter_string.h +++ b/cockatrice/src/game/filters/filter_string.h @@ -4,11 +4,14 @@ #include "../cards/card_database.h" #include "filter_tree.h" +#include #include #include #include #include +inline Q_LOGGING_CATEGORY(FilterStringLog, "filter_string"); + typedef CardInfoPtr CardData; typedef std::function Filter; typedef std::function StringMatcher; diff --git a/cockatrice/src/game/game_scene.cpp b/cockatrice/src/game/game_scene.cpp index cd59473ce..af1e40f96 100644 --- a/cockatrice/src/game/game_scene.cpp +++ b/cockatrice/src/game/game_scene.cpp @@ -39,7 +39,7 @@ void GameScene::retranslateUi() void GameScene::addPlayer(Player *player) { - qDebug() << "GameScene::addPlayer name=" << player->getName(); + qCDebug(GameScenePlayerAdditionRemovalLog) << "GameScene::addPlayer name=" << player->getName(); players << player; addItem(player); connect(player, &Player::sizeChanged, this, &GameScene::rearrange); @@ -48,7 +48,7 @@ void GameScene::addPlayer(Player *player) void GameScene::removePlayer(Player *player) { - qDebug() << "GameScene::removePlayer name=" << player->getName(); + qCDebug(GameScenePlayerAdditionRemovalLog) << "GameScene::removePlayer name=" << player->getName(); for (ZoneViewWidget *zone : zoneViews) { if (zone->getPlayer() == player) { zone->close(); diff --git a/cockatrice/src/game/game_scene.h b/cockatrice/src/game/game_scene.h index e7fc85f23..7654f0b6e 100644 --- a/cockatrice/src/game/game_scene.h +++ b/cockatrice/src/game/game_scene.h @@ -3,9 +3,13 @@ #include #include +#include #include #include +inline Q_LOGGING_CATEGORY(GameSceneLog, "game_scene"); +inline Q_LOGGING_CATEGORY(GameScenePlayerAdditionRemovalLog, "game_scene.player_addition_removal"); + class Player; class ZoneViewWidget; class CardZone; diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index c7666c6a4..d25f3ef63 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -562,7 +562,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T Player::~Player() { - qDebug() << "Player destructor:" << getName(); + qCDebug(PlayerLog) << "Player destructor:" << getName(); static_cast(scene())->removePlayer(this); diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index 2154b4306..b5596928d 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -9,10 +9,13 @@ #include "pb/game_event.pb.h" #include +#include #include #include #include +inline Q_LOGGING_CATEGORY(PlayerLog, "player"); + namespace google { namespace protobuf diff --git a/cockatrice/src/game/zones/card_zone.cpp b/cockatrice/src/game/zones/card_zone.cpp index 4c3fd9db5..893a9b181 100644 --- a/cockatrice/src/game/zones/card_zone.cpp +++ b/cockatrice/src/game/zones/card_zone.cpp @@ -42,7 +42,7 @@ CardZone::CardZone(Player *_p, CardZone::~CardZone() { - qDebug() << "CardZone destructor: " << name; + qCDebug(CardZoneLog) << "CardZone destructor: " << name; for (auto *view : views) { if (view != nullptr) { view->deleteLater(); @@ -147,7 +147,7 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event) void CardZone::addCard(CardItem *card, const bool reorganize, const int x, const int y) { if (!card) { - qDebug() << "CardZone::addCard() card is null, this shouldn't normally happen"; + qCDebug(CardZoneLog) << "CardZone::addCard() card is null, this shouldn't normally happen"; return; } @@ -171,7 +171,7 @@ CardItem *CardZone::getCard(int cardId, const QString &cardName) { CardItem *c = cards.findCard(cardId); if (!c) { - qDebug() << "CardZone::getCard: card id=" << cardId << "not found"; + qCDebug(CardZoneLog) << "CardZone::getCard: card id=" << cardId << "not found"; return nullptr; } // If the card's id is -1, this zone is invisible, @@ -216,7 +216,7 @@ CardItem *CardZone::takeCard(int position, int cardId, bool /*canResize*/) void CardZone::removeCard(CardItem *card) { if (!card) { - qDebug() << "CardZone::removeCard: card is null, this shouldn't normally happen"; + qCDebug(CardZoneLog) << "CardZone::removeCard: card is null, this shouldn't normally happen"; return; } diff --git a/cockatrice/src/game/zones/card_zone.h b/cockatrice/src/game/zones/card_zone.h index f3e889113..20f58d4ba 100644 --- a/cockatrice/src/game/zones/card_zone.h +++ b/cockatrice/src/game/zones/card_zone.h @@ -5,8 +5,11 @@ #include "../board/abstract_graphics_item.h" #include "../cards/card_list.h" +#include #include +inline Q_LOGGING_CATEGORY(CardZoneLog, "card_zone"); + class Player; class ZoneViewZone; class QMenu; diff --git a/cockatrice/src/game/zones/view_zone.cpp b/cockatrice/src/game/zones/view_zone.cpp index 2664587a1..9da4ecc39 100644 --- a/cockatrice/src/game/zones/view_zone.cpp +++ b/cockatrice/src/game/zones/view_zone.cpp @@ -246,7 +246,7 @@ ZoneViewZone::GridSize ZoneViewZone::positionCardsForDisplay(CardList &cards, Ca if (cols < 2) cols = 2; - qDebug() << "reorganizeCards: rows=" << rows << "cols=" << cols; + qCDebug(ViewZoneLog) << "reorganizeCards: rows=" << rows << "cols=" << cols; for (int i = 0; i < cardCount; i++) { CardItem *c = cards.at(i); diff --git a/cockatrice/src/game/zones/view_zone.h b/cockatrice/src/game/zones/view_zone.h index 140cd35d4..6eda0fd23 100644 --- a/cockatrice/src/game/zones/view_zone.h +++ b/cockatrice/src/game/zones/view_zone.h @@ -4,8 +4,11 @@ #include "select_zone.h" #include +#include #include +inline Q_LOGGING_CATEGORY(ViewZoneLog, "view_zone"); + class ZoneViewWidget; class Response; class ServerInfo_Card; diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 3a100683b..bdfd263e0 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -58,7 +58,21 @@ QString translationPath; static void CockatriceLogger(QtMsgType type, const QMessageLogContext &ctx, const QString &message) { - Logger::getInstance().log(type, ctx, message); + QString logMessage = qFormatLogMessage(type, ctx, message); + + // Regular expression to match the full path in the square brackets and extract only the filename and line number + QRegularExpression regex(R"(\[(?:.:)?[\/\\].*[\/\\]([^\/\\]+\:\d+)\])"); + QRegularExpressionMatch match = regex.match(logMessage); + + if (match.hasMatch()) { + // Extract the filename and line number (e.g., "main.cpp:211") + QString filenameLine = match.captured(1); + + // Replace the full path in square brackets with just the filename and line number + logMessage.replace(match.captured(0), QString("[%1]").arg(filenameLine)); + } + + Logger::getInstance().log(type, ctx, logMessage); } #ifdef Q_OS_WIN @@ -127,18 +141,20 @@ void installNewTranslator() bool qtTranslationLoaded = qtTranslator->load(qtNameHint, qtTranslationPath); if (!qtTranslationLoaded) { - qDebug() << "Unable to load qt translation" << qtNameHint << "at" << qtTranslationPath; + qCDebug(QtTranslatorDebug) << "Unable to load qt translation" << qtNameHint << "at" << qtTranslationPath; } else { - qDebug() << "Loaded qt translation" << qtNameHint << "at" << qtTranslationPath; + qCDebug(QtTranslatorDebug) << "Loaded qt translation" << qtNameHint << "at" << qtTranslationPath; } qApp->installTranslator(qtTranslator); QString appNameHint = translationPrefix + "_" + lang; bool appTranslationLoaded = qtTranslator->load(appNameHint, translationPath); if (!appTranslationLoaded) { - qDebug() << "Unable to load" << translationPrefix << "translation" << appNameHint << "at" << translationPath; + qCDebug(QtTranslatorDebug) << "Unable to load" << translationPrefix << "translation" << appNameHint << "at" + << translationPath; } else { - qDebug() << "Loaded" << translationPrefix << "translation" << appNameHint << "at" << translationPath; + qCDebug(QtTranslatorDebug) << "Loaded" << translationPrefix << "translation" << appNameHint << "at" + << translationPath; } qApp->installTranslator(translator); } @@ -163,7 +179,10 @@ int main(int argc, char *argv[]) // Set the QT_LOGGING_CONF environment variable qputenv("QT_LOGGING_CONF", "./qtlogging.ini"); - + qSetMessagePattern( + "\033[0m[%{time yyyy-MM-dd h:mm:ss.zzz} " + "%{if-debug}\033[36mD%{endif}%{if-info}\033[32mI%{endif}%{if-warning}\033[33mW%{endif}%{if-critical}\033[31mC%{" + "endif}%{if-fatal}\033[1;31mF%{endif}\033[0m] [%{function}] - %{message} [%{file}:%{line}]"); QApplication app(argc, argv); QObject::connect(&app, &QApplication::lastWindowClosed, &app, &QApplication::quit); @@ -217,13 +236,13 @@ int main(int argc, char *argv[]) QLocale::setDefault(QLocale::English); - qDebug("main(): starting main program"); + qCDebug(MainLog) << "Starting main program"; MainWindow ui; if (parser.isSet("connect")) { ui.setConnectTo(parser.value("connect")); } - qDebug("main(): MainWindow constructor finished"); + qCDebug(MainLog) << "MainWindow constructor finished"; ui.setWindowIcon(QPixmap("theme:cockatrice")); #if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) @@ -238,7 +257,7 @@ int main(int argc, char *argv[]) SpoilerBackgroundUpdater spoilerBackgroundUpdater; ui.show(); - qDebug("main(): ui.show() finished"); + qCDebug(MainLog) << "ui.show() finished"; // force shortcuts to be shown/hidden in right-click menus, regardless of system defaults qApp->setAttribute(Qt::AA_DontShowShortcutsInContextMenus, !SettingsCache::instance().getShowShortcuts()); diff --git a/cockatrice/src/main.h b/cockatrice/src/main.h index 1d04b30ce..e7dccd631 100644 --- a/cockatrice/src/main.h +++ b/cockatrice/src/main.h @@ -3,6 +3,11 @@ #include "utility/macros.h" +#include + +inline Q_LOGGING_CATEGORY(MainLog, "main"); +inline Q_LOGGING_CATEGORY(QtTranslatorDebug, "qt_translator"); + class CardDatabase; class QString; class QSystemTrayIcon; diff --git a/cockatrice/src/server/user/user_info_connection.cpp b/cockatrice/src/server/user/user_info_connection.cpp index db08f2f78..9882b5398 100644 --- a/cockatrice/src/server/user/user_info_connection.cpp +++ b/cockatrice/src/server/user/user_info_connection.cpp @@ -74,7 +74,7 @@ QStringList UserConnection_Information::getServerInfo(const QString &find) } if (_server.empty()) - qDebug() << "There was a problem!"; + qCDebug(UserInfoConnectionLog) << "There was a problem!"; return _server; } diff --git a/cockatrice/src/server/user/user_info_connection.h b/cockatrice/src/server/user/user_info_connection.h index 137060afe..b2abf65ac 100644 --- a/cockatrice/src/server/user/user_info_connection.h +++ b/cockatrice/src/server/user/user_info_connection.h @@ -4,9 +4,12 @@ #include #include #include +#include #include #include +inline Q_LOGGING_CATEGORY(UserInfoConnectionLog, "user_info_connection"); + class UserConnection_Information { private: diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index 80cd46b01..0b0adb18e 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -144,7 +144,7 @@ QString SettingsCache::getSafeConfigPath(QString configEntry, QString defaultPat // ensure that the defaut path exists and return it if (tmp.isEmpty() || !QDir(tmp).exists()) { if (!QDir().mkpath(defaultPath)) - qDebug() << "[SettingsCache] Could not create folder:" << defaultPath; + qCDebug(SettingsCacheLog) << "[SettingsCache] Could not create folder:" << defaultPath; tmp = defaultPath; } return tmp; @@ -165,7 +165,7 @@ SettingsCache::SettingsCache() // first, figure out if we are running in portable mode isPortableBuild = QFile::exists(qApp->applicationDirPath() + "/portable.dat"); if (isPortableBuild) - qDebug() << "Portable mode enabled"; + qCDebug(SettingsCacheLog) << "Portable mode enabled"; // define a dummy context that will be used where needed QString dummy = QT_TRANSLATE_NOOP("i18n", "English"); diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index 8c75b6789..77833bfbe 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -13,10 +13,13 @@ #include "servers_settings.h" #include "shortcuts_settings.h" +#include #include #include #include +inline Q_LOGGING_CATEGORY(SettingsCacheLog, "settings_cache"); + class ReleaseChannel; // In MB (Increments of 64) diff --git a/cockatrice/src/settings/servers_settings.cpp b/cockatrice/src/settings/servers_settings.cpp index 2ddf99361..01a6c795b 100644 --- a/cockatrice/src/settings/servers_settings.cpp +++ b/cockatrice/src/settings/servers_settings.cpp @@ -76,7 +76,7 @@ QString ServersSettings::getPort(QString defaultPort) { int index = getPrevioushostindex(getPrevioushostName()); QVariant port = getValue(QString("port%1").arg(index), "server", "server_details"); - qDebug() << "getPort() index = " << index << " port.val = " << port.toString(); + qCDebug(ServersSettingsLog) << "getPort() index = " << index << " port.val = " << port.toString(); return port == QVariant() ? std::move(defaultPort) : port.toString(); } @@ -84,7 +84,7 @@ QString ServersSettings::getPlayerName(QString defaultName) { int index = getPrevioushostindex(getPrevioushostName()); QVariant name = getValue(QString("username%1").arg(index), "server", "server_details"); - qDebug() << "getPlayerName() index = " << index << " name.val = " << name.toString(); + qCDebug(ServersSettingsLog) << "getPlayerName() index = " << index << " name.val = " << name.toString(); return name == QVariant() ? std::move(defaultName) : name.toString(); } diff --git a/cockatrice/src/settings/servers_settings.h b/cockatrice/src/settings/servers_settings.h index e5d266e87..9bf5c47d7 100644 --- a/cockatrice/src/settings/servers_settings.h +++ b/cockatrice/src/settings/servers_settings.h @@ -3,10 +3,13 @@ #include "settings_manager.h" +#include #include #define SERVERSETTINGS_DEFAULT_HOST "server.cockatrice.us" #define SERVERSETTINGS_DEFAULT_PORT "4748" +inline Q_LOGGING_CATEGORY(ServersSettingsLog, "servers_settings"); + class ServersSettings : public SettingsManager { Q_OBJECT diff --git a/cockatrice/src/settings/shortcuts_settings.cpp b/cockatrice/src/settings/shortcuts_settings.cpp index bcfc3039a..9618df378 100644 --- a/cockatrice/src/settings/shortcuts_settings.cpp +++ b/cockatrice/src/settings/shortcuts_settings.cpp @@ -67,7 +67,7 @@ void ShortcutsSettings::migrateShortcuts() shortCutsFile.beginGroup(custom); if (shortCutsFile.contains("Textbox/unfocusTextBox")) { - qDebug() + qCDebug(ShortcutsSettingsLog) << "[ShortcutsSettings] Textbox/unfocusTextBox shortcut found. Migrating to Player/unfocusTextBox."; QString unfocusTextBox = shortCutsFile.value("Textbox/unfocusTextBox", "").toString(); this->setShortcuts("Player/unfocusTextBox", unfocusTextBox); @@ -75,7 +75,8 @@ void ShortcutsSettings::migrateShortcuts() } if (shortCutsFile.contains("tab_game/aFocusChat")) { - qDebug() << "[ShortcutsSettings] tab_game/aFocusChat shortcut found. Migrating to Player/aFocusChat."; + qCDebug(ShortcutsSettingsLog) + << "[ShortcutsSettings] tab_game/aFocusChat shortcut found. Migrating to Player/aFocusChat."; QString aFocusChat = shortCutsFile.value("tab_game/aFocusChat", "").toString(); this->setShortcuts("Player/aFocusChat", aFocusChat); shortCutsFile.remove("tab_game/aFocusChat"); diff --git a/cockatrice/src/settings/shortcuts_settings.h b/cockatrice/src/settings/shortcuts_settings.h index 91a76d633..ce51b5126 100644 --- a/cockatrice/src/settings/shortcuts_settings.h +++ b/cockatrice/src/settings/shortcuts_settings.h @@ -3,8 +3,11 @@ #include #include +#include #include +inline Q_LOGGING_CATEGORY(ShortcutsSettingsLog, "shortcuts_settings"); + class ShortcutGroup { public: