From df722a72c18457c71833e03cfad9caccff3cf963 Mon Sep 17 00:00:00 2001 From: Steve Wills Date: Sat, 21 Nov 2020 10:20:10 -0500 Subject: [PATCH] Switch to QT Category logging (#2206) Co-authored-by: Rasmus Karlsson --- chatterino.pro | 4 + src/Application.cpp | 4 +- src/RunGui.cpp | 3 +- src/common/Args.cpp | 7 +- src/common/DownloadManager.cpp | 8 +- src/common/NetworkPrivate.cpp | 5 +- src/common/NetworkRequest.cpp | 3 +- src/common/NetworkResult.cpp | 7 +- src/common/QLogging.cpp | 37 ++++ src/common/QLogging.hpp | 29 +++ src/common/WindowDescriptors.cpp | 8 +- src/controllers/filters/parser/Tokenizer.cpp | 16 +- .../notifications/NotificationController.cpp | 10 +- src/debug/Benchmark.cpp | 5 +- src/debug/Benchmark.hpp | 1 - src/main.cpp | 15 +- src/messages/Image.cpp | 11 +- src/messages/SharedMessageBuilder.cpp | 11 +- src/messages/layouts/MessageLayoutElement.cpp | 3 +- src/providers/IvrApi.cpp | 6 +- src/providers/bttv/BttvEmotes.cpp | 11 +- src/providers/emoji/Emojis.cpp | 12 +- src/providers/ffz/FfzEmotes.cpp | 15 +- src/providers/irc/AbstractIrcServer.cpp | 8 +- src/providers/irc/IrcServer.cpp | 3 +- src/providers/twitch/ChannelPointReward.cpp | 25 ++- .../twitch/ChatterinoWebSocketppLogger.hpp | 199 ++++++++++++++++++ src/providers/twitch/IrcMessageHandler.cpp | 18 +- src/providers/twitch/PubsubClient.cpp | 170 +++++++++------ src/providers/twitch/PubsubClient.hpp | 22 +- src/providers/twitch/PubsubHelpers.hpp | 7 +- src/providers/twitch/TwitchAccount.cpp | 41 ++-- src/providers/twitch/TwitchAccountManager.cpp | 21 +- src/providers/twitch/TwitchChannel.cpp | 16 +- src/providers/twitch/TwitchHelpers.cpp | 3 +- src/providers/twitch/TwitchIrcServer.cpp | 3 +- src/providers/twitch/TwitchMessageBuilder.cpp | 16 +- src/providers/twitch/api/Helix.cpp | 5 +- src/providers/twitch/api/Kraken.cpp | 3 +- src/singletons/NativeMessaging.cpp | 22 +- src/singletons/Updates.cpp | 12 +- src/singletons/WindowManager.cpp | 7 +- src/singletons/helper/LoggingChannel.cpp | 5 +- src/util/NuulsUploader.cpp | 3 +- src/util/StreamLink.cpp | 5 +- src/widgets/AttachedWindow.cpp | 6 +- src/widgets/Notebook.cpp | 3 +- src/widgets/Scrollbar.cpp | 12 +- src/widgets/dialogs/LoginDialog.cpp | 7 +- src/widgets/dialogs/QualityPopup.cpp | 4 +- src/widgets/helper/ChannelView.cpp | 6 +- src/widgets/settingspages/AboutPage.cpp | 4 +- src/widgets/settingspages/GeneralPageView.hpp | 3 +- src/widgets/splits/Split.cpp | 4 +- 54 files changed, 655 insertions(+), 239 deletions(-) create mode 100644 src/common/QLogging.cpp create mode 100644 src/common/QLogging.hpp create mode 100644 src/providers/twitch/ChatterinoWebSocketppLogger.hpp diff --git a/chatterino.pro b/chatterino.pro index af9f9f1ea..7dd4d1e9a 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -133,6 +133,7 @@ SOURCES += \ src/common/UsernameSet.cpp \ src/common/Version.cpp \ src/common/WindowDescriptors.cpp \ + src/common/QLogging.cpp \ src/controllers/accounts/Account.cpp \ src/controllers/accounts/AccountController.cpp \ src/controllers/accounts/AccountModel.cpp \ @@ -348,6 +349,7 @@ HEADERS += \ src/common/UniqueAccess.hpp \ src/common/UsernameSet.hpp \ src/common/Version.hpp \ + src/common/QLogging.hpp \ src/controllers/accounts/Account.hpp \ src/controllers/accounts/AccountController.hpp \ src/controllers/accounts/AccountModel.hpp \ @@ -418,6 +420,7 @@ HEADERS += \ src/providers/IvrApi.hpp \ src/providers/LinkResolver.hpp \ src/providers/twitch/ChannelPointReward.hpp \ + src/providers/twitch/ChatterinoWebSocketppLogger.hpp \ src/providers/twitch/api/Helix.hpp \ src/providers/twitch/api/Kraken.hpp \ src/providers/twitch/EmoteValue.hpp \ @@ -620,6 +623,7 @@ CONFIG(debug, debug|release) { message("Building Chatterino2 DEBUG") } else { message("Building Chatterino2 RELEASE") + DEFINES += DEBUG_OFF } message("Injected git values: $$git_commit ($$git_release) $$git_hash") diff --git a/src/Application.cpp b/src/Application.cpp index 2b6277946..93549c1e6 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -3,6 +3,7 @@ #include #include "common/Args.hpp" +#include "common/QLogging.hpp" #include "common/Version.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/commands/CommandController.hpp" @@ -339,7 +340,8 @@ void Application::initPubsub() } else { - qDebug() << "Couldn't find channel id of point reward"; + qCDebug(chatterinoApp) + << "Couldn't find channel id of point reward"; } }); diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 21dcb15e9..4a1aa26d4 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -12,6 +12,7 @@ #include "common/Args.hpp" #include "common/Modes.hpp" #include "common/NetworkManager.hpp" +#include "common/QLogging.hpp" #include "singletons/Paths.hpp" #include "singletons/Resources.hpp" #include "singletons/Settings.hpp" @@ -144,7 +145,7 @@ namespace { // improved in the future. void clearCache(const QDir &dir) { - qDebug() << "[Cache] cleared cache"; + qCDebug(chatterinoCache) << "[Cache] cleared cache"; QStringList toBeRemoved; diff --git a/src/common/Args.cpp b/src/common/Args.cpp index 3db1474b3..e85b40b59 100644 --- a/src/common/Args.cpp +++ b/src/common/Args.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace chatterino { @@ -38,13 +39,13 @@ Args::Args(const QApplication &app) if (!parser.parse(app.arguments())) { - qDebug() << "Warning: Unhandled options:" - << parser.unknownOptionNames(); + qCWarning(chatterinoArgs) + << "Unhandled options:" << parser.unknownOptionNames(); } if (parser.isSet("help")) { - qDebug().noquote() << parser.helpText(); + qCInfo(chatterinoArgs).noquote() << parser.helpText(); ::exit(EXIT_SUCCESS); } diff --git a/src/common/DownloadManager.cpp b/src/common/DownloadManager.cpp index 6a239370a..3a1f1dc49 100644 --- a/src/common/DownloadManager.cpp +++ b/src/common/DownloadManager.cpp @@ -3,6 +3,7 @@ #include "singletons/Paths.hpp" #include +#include "common/QLogging.hpp" namespace chatterino { @@ -40,7 +41,8 @@ void DownloadManager::setFile(QString fileURL, const QString &channelName) void DownloadManager::onDownloadProgress(qint64 bytesRead, qint64 bytesTotal) { - qDebug() << "Download progress: " << bytesRead << "/" << bytesTotal; + qCDebug(chatterinoCommon) + << "Download progress: " << bytesRead << "/" << bytesTotal; } void DownloadManager::onFinished(QNetworkReply *reply) @@ -48,11 +50,11 @@ void DownloadManager::onFinished(QNetworkReply *reply) switch (reply->error()) { case QNetworkReply::NoError: { - qDebug("file is downloaded successfully."); + qCDebug(chatterinoCommon) << "file is downloaded successfully."; } break; default: { - qDebug() << reply->errorString().toLatin1(); + qCDebug(chatterinoCommon) << reply->errorString().toLatin1(); }; } diff --git a/src/common/NetworkPrivate.cpp b/src/common/NetworkPrivate.cpp index 3e98be924..dc1ffd436 100644 --- a/src/common/NetworkPrivate.cpp +++ b/src/common/NetworkPrivate.cpp @@ -11,6 +11,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace chatterino { @@ -123,7 +124,7 @@ void loadUncached(const std::shared_ptr &data) if (reply == nullptr) { - qDebug() << "Unhandled request type"; + qCDebug(chatterinoCommon) << "Unhandled request type"; return; } @@ -131,7 +132,7 @@ void loadUncached(const std::shared_ptr &data) { QObject::connect( data->timer_, &QTimer::timeout, worker, [reply, data]() { - qDebug() << "Aborted!"; + qCDebug(chatterinoCommon) << "Aborted!"; reply->abort(); if (data->onError_) { diff --git a/src/common/NetworkRequest.cpp b/src/common/NetworkRequest.cpp index ffb64f708..1041fafe5 100644 --- a/src/common/NetworkRequest.cpp +++ b/src/common/NetworkRequest.cpp @@ -12,6 +12,7 @@ #include #include #include +#include "common/QLogging.hpp" #include @@ -167,7 +168,7 @@ void NetworkRequest::execute() if (this->data->cache_ && this->data->requestType_ != NetworkRequestType::Get) { - qDebug() << "Can only cache GET requests!"; + qCDebug(chatterinoCommon) << "Can only cache GET requests!"; this->data->cache_ = false; } diff --git a/src/common/NetworkResult.cpp b/src/common/NetworkResult.cpp index feaf40bc5..c2cb45e1d 100644 --- a/src/common/NetworkResult.cpp +++ b/src/common/NetworkResult.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace chatterino { @@ -43,9 +44,9 @@ rapidjson::Document NetworkResult::parseRapidJson() const if (result.Code() != rapidjson::kParseErrorNone) { - qDebug() << "JSON parse error:" - << rapidjson::GetParseError_En(result.Code()) << "(" - << result.Offset() << ")"; + qCWarning(chatterinoCommon) + << "JSON parse error:" << rapidjson::GetParseError_En(result.Code()) + << "(" << result.Offset() << ")"; return ret; } diff --git a/src/common/QLogging.cpp b/src/common/QLogging.cpp new file mode 100644 index 000000000..ca54d6980 --- /dev/null +++ b/src/common/QLogging.cpp @@ -0,0 +1,37 @@ +#include "common/QLogging.hpp" + +#ifdef DEBUG_OFF +static constexpr QtMsgType logThreshold = QtWarningMsg; +#else +static constexpr QtMsgType logThreshold = QtDebugMsg; +#endif + +Q_LOGGING_CATEGORY(chatterinoApp, "chatterino.app", logThreshold); +Q_LOGGING_CATEGORY(chatterinoArgs, "chatterino.args", logThreshold); +Q_LOGGING_CATEGORY(chatterinoBenchmark, "chatterino.benchmark", logThreshold); +Q_LOGGING_CATEGORY(chatterinoBttv, "chatterino.bttv", logThreshold); +Q_LOGGING_CATEGORY(chatterinoCommon, "chatterino.cache", logThreshold); +Q_LOGGING_CATEGORY(chatterinoCache, "chatterino.common", logThreshold); +Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold); +Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold); +Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold); +Q_LOGGING_CATEGORY(chatterinoImage, "chatterino.image", logThreshold); +Q_LOGGING_CATEGORY(chatterinoIrc, "chatterino.irc", logThreshold); +Q_LOGGING_CATEGORY(chatterinoIvr, "chatterino.ivr", logThreshold); +Q_LOGGING_CATEGORY(chatterinoMain, "chatterino.main", logThreshold); +Q_LOGGING_CATEGORY(chatterinoMessage, "chatterino.message", logThreshold); +Q_LOGGING_CATEGORY(chatterinoNativeMessage, "chatterino.nativemessage", + logThreshold); +Q_LOGGING_CATEGORY(chatterinoNotification, "chatterino.notification", + logThreshold); +Q_LOGGING_CATEGORY(chatterinoNuulsuploader, "chatterino.nuulsuploader", + logThreshold); +Q_LOGGING_CATEGORY(chatterinoPubsub, "chatterino.pubsub", logThreshold); +Q_LOGGING_CATEGORY(chatterinoStreamlink, "chatterino.streamlink", logThreshold); +Q_LOGGING_CATEGORY(chatterinoTokenizer, "chatterino.tokenizer", logThreshold); +Q_LOGGING_CATEGORY(chatterinoTwitch, "chatterino.twitch", logThreshold); +Q_LOGGING_CATEGORY(chatterinoUpdate, "chatterino.update", logThreshold); +Q_LOGGING_CATEGORY(chatterinoWebsocket, "chatterino.websocket", logThreshold); +Q_LOGGING_CATEGORY(chatterinoWidget, "chatterino.widget", logThreshold); +Q_LOGGING_CATEGORY(chatterinoWindowmanager, "chatterino.windowmanager", + logThreshold); diff --git a/src/common/QLogging.hpp b/src/common/QLogging.hpp new file mode 100644 index 000000000..82e0f3e4a --- /dev/null +++ b/src/common/QLogging.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +Q_DECLARE_LOGGING_CATEGORY(chatterinoApp); +Q_DECLARE_LOGGING_CATEGORY(chatterinoArgs); +Q_DECLARE_LOGGING_CATEGORY(chatterinoBenchmark); +Q_DECLARE_LOGGING_CATEGORY(chatterinoBttv); +Q_DECLARE_LOGGING_CATEGORY(chatterinoCache); +Q_DECLARE_LOGGING_CATEGORY(chatterinoCommon); +Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji); +Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes); +Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper); +Q_DECLARE_LOGGING_CATEGORY(chatterinoImage); +Q_DECLARE_LOGGING_CATEGORY(chatterinoIrc); +Q_DECLARE_LOGGING_CATEGORY(chatterinoIvr); +Q_DECLARE_LOGGING_CATEGORY(chatterinoMain); +Q_DECLARE_LOGGING_CATEGORY(chatterinoMessage); +Q_DECLARE_LOGGING_CATEGORY(chatterinoNativeMessage); +Q_DECLARE_LOGGING_CATEGORY(chatterinoNotification); +Q_DECLARE_LOGGING_CATEGORY(chatterinoNuulsuploader); +Q_DECLARE_LOGGING_CATEGORY(chatterinoPubsub); +Q_DECLARE_LOGGING_CATEGORY(chatterinoStreamlink); +Q_DECLARE_LOGGING_CATEGORY(chatterinoTokenizer); +Q_DECLARE_LOGGING_CATEGORY(chatterinoTwitch); +Q_DECLARE_LOGGING_CATEGORY(chatterinoUpdate); +Q_DECLARE_LOGGING_CATEGORY(chatterinoWebsocket); +Q_DECLARE_LOGGING_CATEGORY(chatterinoWidget); +Q_DECLARE_LOGGING_CATEGORY(chatterinoWindowmanager); diff --git a/src/common/WindowDescriptors.cpp b/src/common/WindowDescriptors.cpp index 6d4585aff..ed86a952c 100644 --- a/src/common/WindowDescriptors.cpp +++ b/src/common/WindowDescriptors.cpp @@ -1,5 +1,6 @@ #include "common/WindowDescriptors.hpp" +#include "common/QLogging.hpp" #include "widgets/Window.hpp" namespace chatterino { @@ -126,7 +127,7 @@ WindowLayout WindowLayout::loadFromFile(const QString &path) { if (hasSetAMainWindow) { - qDebug() + qCDebug(chatterinoCommon) << "Window Layout file contains more than one Main window " "- demoting to Popup type"; type = WindowType::Popup; @@ -180,8 +181,9 @@ WindowLayout WindowLayout::loadFromFile(const QString &path) { if (hasSetASelectedTab) { - qDebug() << "Window contains more than one selected tab - " - "demoting to unselected"; + qCDebug(chatterinoCommon) + << "Window contains more than one selected tab - " + "demoting to unselected"; tab.selected_ = false; } hasSetASelectedTab = true; diff --git a/src/controllers/filters/parser/Tokenizer.cpp b/src/controllers/filters/parser/Tokenizer.cpp index 08bc2b9f3..d3e6f3b14 100644 --- a/src/controllers/filters/parser/Tokenizer.cpp +++ b/src/controllers/filters/parser/Tokenizer.cpp @@ -1,4 +1,5 @@ #include "controllers/filters/parser/Tokenizer.hpp" +#include "common/QLogging.hpp" namespace filterparser { @@ -70,21 +71,24 @@ void Tokenizer::debug() { if (this->i_ > 0) { - qDebug() << "= current" << this->tokens_.at(this->i_ - 1); - qDebug() << "= current type" << this->tokenTypes_.at(this->i_ - 1); + qCDebug(chatterinoTokenizer) + << "= current" << this->tokens_.at(this->i_ - 1); + qCDebug(chatterinoTokenizer) + << "= current type" << this->tokenTypes_.at(this->i_ - 1); } else { - qDebug() << "= no current"; + qCDebug(chatterinoTokenizer) << "= no current"; } if (this->hasNext()) { - qDebug() << "= next" << this->tokens_.at(this->i_); - qDebug() << "= next type" << this->tokenTypes_.at(this->i_); + qCDebug(chatterinoTokenizer) << "= next" << this->tokens_.at(this->i_); + qCDebug(chatterinoTokenizer) + << "= next type" << this->tokenTypes_.at(this->i_); } else { - qDebug() << "= no next"; + qCDebug(chatterinoTokenizer) << "= no next"; } } diff --git a/src/controllers/notifications/NotificationController.cpp b/src/controllers/notifications/NotificationController.cpp index fb07b3dee..7ca106eb9 100644 --- a/src/controllers/notifications/NotificationController.cpp +++ b/src/controllers/notifications/NotificationController.cpp @@ -3,6 +3,7 @@ #include "Application.hpp" #include "common/NetworkRequest.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" #include "controllers/notifications/NotificationModel.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "providers/twitch/api/Helix.hpp" @@ -146,8 +147,8 @@ void NotificationController::getFakeTwitchChannelLiveStatus( getHelix()->getStreamByName( channelName, [channelName, this](bool live, const auto &stream) { - qDebug() << "[TwitchChannel" << channelName - << "] Refreshing live status"; + qCDebug(chatterinoNotification) << "[TwitchChannel" << channelName + << "] Refreshing live status"; if (!live) { @@ -185,8 +186,9 @@ void NotificationController::getFakeTwitchChannelLiveStatus( fakeTwitchChannels.push_back(channelName); }, [channelName, this] { - qDebug() << "[TwitchChannel" << channelName - << "] Refreshing live status (Missing ID)"; + qCDebug(chatterinoNotification) + << "[TwitchChannel" << channelName + << "] Refreshing live status (Missing ID)"; this->removeFakeChannel(channelName); }); } diff --git a/src/debug/Benchmark.cpp b/src/debug/Benchmark.cpp index 12475f06d..58c6cea42 100644 --- a/src/debug/Benchmark.cpp +++ b/src/debug/Benchmark.cpp @@ -1,4 +1,5 @@ #include "Benchmark.hpp" +#include "common/QLogging.hpp" namespace chatterino { @@ -10,8 +11,8 @@ BenchmarkGuard::BenchmarkGuard(const QString &_name) BenchmarkGuard::~BenchmarkGuard() { - qDebug() << this->name_ << float(timer_.nsecsElapsed()) / 1000000.0f - << "ms"; + qCDebug(chatterinoBenchmark) + << this->name_ << float(timer_.nsecsElapsed()) / 1000000.0f << "ms"; } qreal BenchmarkGuard::getElapsedMs() diff --git a/src/debug/Benchmark.hpp b/src/debug/Benchmark.hpp index b29dce802..66e9732f3 100644 --- a/src/debug/Benchmark.hpp +++ b/src/debug/Benchmark.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 72c577e07..aa86dce66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include #include @@ -9,6 +8,7 @@ #include "RunGui.hpp" #include "common/Args.hpp" #include "common/Modes.hpp" +#include "common/QLogging.hpp" #include "common/Version.hpp" #include "providers/IvrApi.hpp" #include "providers/twitch/api/Helix.hpp" @@ -37,12 +37,13 @@ int main(int argc, char **argv) else if (getArgs().printVersion) { auto version = Version::instance(); - qInfo().noquote() << QString("%1 (commit %2%3)") - .arg(version.fullVersion()) - .arg(version.commitHash()) - .arg(Modes::instance().isNightly - ? ", " + version.dateOfBuild() - : ""); + qCInfo(chatterinoMain).noquote() + << QString("%1 (commit %2%3)") + .arg(version.fullVersion()) + .arg(version.commitHash()) + .arg(Modes::instance().isNightly + ? ", " + version.dateOfBuild() + : ""); } else { diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 41a0c21aa..9a29d1596 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -12,6 +12,7 @@ #include "Application.hpp" #include "common/Common.hpp" #include "common/NetworkRequest.hpp" +#include "common/QLogging.hpp" #include "debug/AssertInGuiThread.hpp" #include "debug/Benchmark.hpp" #include "singletons/Emotes.hpp" @@ -130,8 +131,9 @@ namespace detail { if (reader.imageCount() == 0) { - qDebug() << "Error while reading image" << url.string << ": '" - << reader.errorString() << "'"; + qCDebug(chatterinoImage) + << "Error while reading image" << url.string << ": '" + << reader.errorString() << "'"; return frames; } @@ -149,8 +151,9 @@ namespace detail { if (frames.size() == 0) { - qDebug() << "Error while reading image" << url.string << ": '" - << reader.errorString() << "'"; + qCDebug(chatterinoImage) + << "Error while reading image" << url.string << ": '" + << reader.errorString() << "'"; } return frames; diff --git a/src/messages/SharedMessageBuilder.cpp b/src/messages/SharedMessageBuilder.cpp index 244a2682b..d3da6b1c7 100644 --- a/src/messages/SharedMessageBuilder.cpp +++ b/src/messages/SharedMessageBuilder.cpp @@ -1,6 +1,7 @@ #include "messages/SharedMessageBuilder.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "controllers/ignores/IgnorePhrase.hpp" #include "messages/Message.hpp" #include "messages/MessageElement.hpp" @@ -88,8 +89,9 @@ bool SharedMessageBuilder::isIgnored() const { if (phrase.isBlock() && phrase.isMatch(this->originalMessage_)) { - qDebug() << "Blocking message because it contains ignored phrase" - << phrase.getPattern(); + qCDebug(chatterinoMessage) + << "Blocking message because it contains ignored phrase" + << phrase.getPattern(); return true; } } @@ -202,8 +204,9 @@ void SharedMessageBuilder::parseHighlights() { continue; } - qDebug() << "Highlight because user" << this->ircMessage->nick() - << "sent a message"; + qCDebug(chatterinoMessage) + << "Highlight because user" << this->ircMessage->nick() + << "sent a message"; this->message().flags.set(MessageFlag::Highlighted); this->message().highlightColor = userHighlight.getColor(); diff --git a/src/messages/layouts/MessageLayoutElement.cpp b/src/messages/layouts/MessageLayoutElement.cpp index dbcfe78aa..34e9dcbb4 100644 --- a/src/messages/layouts/MessageLayoutElement.cpp +++ b/src/messages/layouts/MessageLayoutElement.cpp @@ -1,6 +1,7 @@ #include "messages/layouts/MessageLayoutElement.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "messages/Emote.hpp" #include "messages/Image.hpp" #include "messages/MessageElement.hpp" @@ -422,7 +423,7 @@ void MultiColorTextLayoutElement::paint(QPainter &painter) for (const auto &segment : this->segments_) { - // qDebug() << "Draw segment:" << segment.text; + qCDebug(chatterinoMessage) << "Draw segment:" << segment.text; painter.setPen(segment.color); painter.drawText(QRectF(this->getRect().x() + xOffset, this->getRect().y(), 10000, 10000), diff --git a/src/providers/IvrApi.cpp b/src/providers/IvrApi.cpp index e2163ecfe..e30abdba5 100644 --- a/src/providers/IvrApi.cpp +++ b/src/providers/IvrApi.cpp @@ -1,6 +1,7 @@ #include "IvrApi.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" #include @@ -23,8 +24,9 @@ void IvrApi::getSubage(QString userName, QString channelName, return Success; }) .onError([failureCallback](NetworkResult result) { - qDebug() << "Failed IVR API Call!" << result.status() - << QString(result.getData()); + qCWarning(chatterinoIvr) + << "Failed IVR API Call!" << result.status() + << QString(result.getData()); failureCallback(); }) .execute(); diff --git a/src/providers/bttv/BttvEmotes.cpp b/src/providers/bttv/BttvEmotes.cpp index 815e6afa4..e3943a4b1 100644 --- a/src/providers/bttv/BttvEmotes.cpp +++ b/src/providers/bttv/BttvEmotes.cpp @@ -5,6 +5,7 @@ #include "common/Common.hpp" #include "common/NetworkRequest.hpp" +#include "common/QLogging.hpp" #include "messages/Emote.hpp" #include "messages/Image.hpp" #include "messages/ImageSet.hpp" @@ -178,15 +179,17 @@ void BttvEmotes::loadChannel(std::weak_ptr channel, else if (result.status() == NetworkResult::timedoutStatus) { // TODO: Auto retry in case of a timeout, with a delay - qDebug() << "Fetching BTTV emotes for channel" << channelId - << "failed due to timeout"; + qCWarning(chatterinoBttv) + << "Fetching BTTV emotes for channel" << channelId + << "failed due to timeout"; shared->addMessage(makeSystemMessage( "Failed to fetch BetterTTV channel emotes. (timed out)")); } else { - qDebug() << "Error fetching BTTV emotes for channel" - << channelId << ", error" << result.status(); + qCWarning(chatterinoBttv) + << "Error fetching BTTV emotes for channel" << channelId + << ", error" << result.status(); shared->addMessage( makeSystemMessage("Failed to fetch BetterTTV channel " "emotes. (unknown error)")); diff --git a/src/providers/emoji/Emojis.cpp b/src/providers/emoji/Emojis.cpp index 670793e7c..d578fb552 100644 --- a/src/providers/emoji/Emojis.cpp +++ b/src/providers/emoji/Emojis.cpp @@ -10,6 +10,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace chatterino { namespace { @@ -131,9 +132,9 @@ void Emojis::loadEmojis() if (result.Code() != rapidjson::kParseErrorNone) { - qDebug() << "JSON parse error:" - << rapidjson::GetParseError_En(result.Code()) << "(" - << result.Offset() << ")"; + qCWarning(chatterinoEmoji) + << "JSON parse error:" << rapidjson::GetParseError_En(result.Code()) + << "(" << result.Offset() << ")"; return; } @@ -165,8 +166,9 @@ void Emojis::loadEmojis() auto toneNameIt = toneNames.find(tone); if (toneNameIt == toneNames.end()) { - qDebug() << "Tone with key" << tone.c_str() - << "does not exist in tone names map"; + qCDebug(chatterinoEmoji) + << "Tone with key" << tone.c_str() + << "does not exist in tone names map"; continue; } diff --git a/src/providers/ffz/FfzEmotes.cpp b/src/providers/ffz/FfzEmotes.cpp index ffef47e91..7812d86f4 100644 --- a/src/providers/ffz/FfzEmotes.cpp +++ b/src/providers/ffz/FfzEmotes.cpp @@ -4,6 +4,7 @@ #include "common/NetworkRequest.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" #include "messages/Emote.hpp" #include "messages/Image.hpp" #include "messages/MessageBuilder.hpp" @@ -195,8 +196,8 @@ void FfzEmotes::loadChannel( std::function)> modBadgeCallback, bool manualRefresh) { - qDebug() << "[FFZEmotes] Reload FFZ Channel Emotes for channel" - << channelId; + qCDebug(chatterinoFfzemotes) + << "[FFZEmotes] Reload FFZ Channel Emotes for channel" << channelId; NetworkRequest("https://api.frankerfacez.com/v1/room/id/" + channelId) @@ -230,16 +231,18 @@ void FfzEmotes::loadChannel( else if (result.status() == NetworkResult::timedoutStatus) { // TODO: Auto retry in case of a timeout, with a delay - qDebug() << "Fetching FFZ emotes for channel" << channelId - << "failed due to timeout"; + qCWarning(chatterinoFfzemotes) + << "Fetching FFZ emotes for channel" << channelId + << "failed due to timeout"; shared->addMessage( makeSystemMessage("Failed to fetch FrankerFaceZ channel " "emotes. (timed out)")); } else { - qDebug() << "Error fetching FFZ emotes for channel" << channelId - << ", error" << result.status(); + qCWarning(chatterinoFfzemotes) + << "Error fetching FFZ emotes for channel" << channelId + << ", error" << result.status(); shared->addMessage( makeSystemMessage("Failed to fetch FrankerFaceZ channel " "emotes. (unknown error)")); diff --git a/src/providers/irc/AbstractIrcServer.cpp b/src/providers/irc/AbstractIrcServer.cpp index 5ebea7da1..9cc7a4f74 100644 --- a/src/providers/irc/AbstractIrcServer.cpp +++ b/src/providers/irc/AbstractIrcServer.cpp @@ -2,6 +2,7 @@ #include "common/Channel.hpp" #include "common/Common.hpp" +#include "common/QLogging.hpp" #include "messages/LimitedQueueSnapshot.hpp" #include "messages/Message.hpp" #include "messages/MessageBuilder.hpp" @@ -76,7 +77,8 @@ AbstractIrcServer::AbstractIrcServer() if (!this->readConnection_->isConnected()) { - qDebug() << "Trying to reconnect..." << this->falloffCounter_; + qCDebug(chatterinoIrc) + << "Trying to reconnect..." << this->falloffCounter_; this->connect(); } }); @@ -195,8 +197,8 @@ ChannelPtr AbstractIrcServer::getOrAddChannel(const QString &dirtyChannelName) chan->destroyed.connect([this, channelName] { // fourtf: issues when the server itself is destroyed - qDebug() << "[AbstractIrcServer::addChannel]" << channelName - << "was destroyed"; + qCDebug(chatterinoIrc) << "[AbstractIrcServer::addChannel]" + << channelName << "was destroyed"; this->channels.remove(channelName); if (this->readConnection_) diff --git a/src/providers/irc/IrcServer.cpp b/src/providers/irc/IrcServer.cpp index 006e55acb..34d33bb59 100644 --- a/src/providers/irc/IrcServer.cpp +++ b/src/providers/irc/IrcServer.cpp @@ -3,6 +3,7 @@ #include #include +#include "common/QLogging.hpp" #include "messages/Message.hpp" #include "providers/irc/Irc2.hpp" #include "providers/irc/IrcChannel2.hpp" @@ -187,7 +188,7 @@ void IrcServer::privateMessageReceived(Communi::IrcPrivateMessage *message) } else { - qDebug() << "message ignored :rage:"; + qCDebug(chatterinoIrc) << "message ignored :rage:"; } } } diff --git a/src/providers/twitch/ChannelPointReward.cpp b/src/providers/twitch/ChannelPointReward.cpp index 95d8d9890..479a334b5 100644 --- a/src/providers/twitch/ChannelPointReward.cpp +++ b/src/providers/twitch/ChannelPointReward.cpp @@ -1,4 +1,5 @@ #include "ChannelPointReward.hpp" +#include "common/QLogging.hpp" #include "util/RapidjsonHelpers.hpp" namespace chatterino { @@ -9,7 +10,8 @@ QString parseRewardImage(const rapidjson::Value &obj, const char *key, QString url; if (!(result = rj::getSafe(obj, key, url))) { - qDebug() << "No url value found for key in reward image object:" << key; + qCDebug(chatterinoTwitch) + << "No url value found for key in reward image object:" << key; return ""; } @@ -22,7 +24,7 @@ ChannelPointReward::ChannelPointReward(rapidjson::Value &redemption) if (!(this->hasParsedSuccessfully = rj::getSafeObject(redemption, "user", user))) { - qDebug() << "No user info found for redemption"; + qCDebug(chatterinoTwitch) << "No user info found for redemption"; return; } @@ -30,41 +32,42 @@ ChannelPointReward::ChannelPointReward(rapidjson::Value &redemption) if (!(this->hasParsedSuccessfully = rj::getSafeObject(redemption, "reward", reward))) { - qDebug() << "No reward info found for redemption"; + qCDebug(chatterinoTwitch) << "No reward info found for redemption"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(reward, "id", this->id))) { - qDebug() << "No id found for reward"; + qCDebug(chatterinoTwitch) << "No id found for reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(reward, "channel_id", this->channelId))) { - qDebug() << "No channel_id found for reward"; + qCDebug(chatterinoTwitch) << "No channel_id found for reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(reward, "title", this->title))) { - qDebug() << "No title found for reward"; + qCDebug(chatterinoTwitch) << "No title found for reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(reward, "cost", this->cost))) { - qDebug() << "No cost found for reward"; + qCDebug(chatterinoTwitch) << "No cost found for reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe( reward, "is_user_input_required", this->isUserInputRequired))) { - qDebug() << "No information if user input is required found for reward"; + qCDebug(chatterinoTwitch) + << "No information if user input is required found for reward"; return; } @@ -105,21 +108,21 @@ void ChannelPointReward::parseUser(rapidjson::Value &user) { if (!(this->hasParsedSuccessfully = rj::getSafe(user, "id", this->user.id))) { - qDebug() << "No id found for user in reward"; + qCDebug(chatterinoTwitch) << "No id found for user in reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(user, "login", this->user.login))) { - qDebug() << "No login name found for user in reward"; + qCDebug(chatterinoTwitch) << "No login name found for user in reward"; return; } if (!(this->hasParsedSuccessfully = rj::getSafe(user, "display_name", this->user.displayName))) { - qDebug() << "No display name found for user in reward"; + qCDebug(chatterinoTwitch) << "No display name found for user in reward"; return; } } diff --git a/src/providers/twitch/ChatterinoWebSocketppLogger.hpp b/src/providers/twitch/ChatterinoWebSocketppLogger.hpp new file mode 100644 index 000000000..951149dd6 --- /dev/null +++ b/src/providers/twitch/ChatterinoWebSocketppLogger.hpp @@ -0,0 +1,199 @@ +/* + * Copyright (c) 2020, Peter Thorson, Steve Wills. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the WebSocket++ Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef CHATTERINOWEBSOCKETPPLOGGER_HPP +#define CHATTERINOWEBSOCKETPPLOGGER_HPP + +#include +#include +#include +#include +#include "common/QLogging.hpp" + +namespace websocketpp { +namespace log { + + template + class chatterinowebsocketpplogger : public basic + { + public: + typedef chatterinowebsocketpplogger base; + + chatterinowebsocketpplogger( + channel_type_hint::value) + : m_static_channels(0xffffffff) + , m_dynamic_channels(0) + { + } + + chatterinowebsocketpplogger(std::ostream *) + : m_static_channels(0xffffffff) + , m_dynamic_channels(0) + { + } + + chatterinowebsocketpplogger( + level c, channel_type_hint::value) + : m_static_channels(c) + , m_dynamic_channels(0) + { + } + + chatterinowebsocketpplogger(level c, std::ostream *) + : m_static_channels(c) + , m_dynamic_channels(0) + { + } + + ~chatterinowebsocketpplogger() + { + } + + chatterinowebsocketpplogger( + chatterinowebsocketpplogger const &other) + : m_static_channels(other.m_static_channels) + , m_dynamic_channels(other.m_dynamic_channels) + { + } + +#ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ + chatterinowebsocketpplogger &operator=( + chatterinowebsocketpplogger const &) = delete; +#endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ + +#ifdef _WEBSOCKETPP_MOVE_SEMANTICS_ + /// Move constructor + chatterinowebsocketpplogger( + chatterinowebsocketpplogger &&other) + : m_static_channels(other.m_static_channels) + , m_dynamic_channels(other.m_dynamic_channels) + { + } +# ifdef _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ + // no move assignment operator because of const member variables + chatterinowebsocketpplogger &operator=( + chatterinowebsocketpplogger &&) = delete; +# endif // _WEBSOCKETPP_DEFAULT_DELETE_FUNCTIONS_ +#endif // _WEBSOCKETPP_MOVE_SEMANTICS_ + + /// Explicitly do nothing, this logger doesn't support changing ostream + void set_ostream(std::ostream *) + { + } + + /// Dynamically enable the given list of channels + /** + * @param channels The package of channels to enable + */ + void set_channels(level channels) + { + if (channels == names::none) + { + clear_channels(names::all); + return; + } + + scoped_lock_type lock(m_lock); + m_dynamic_channels |= (channels & m_static_channels); + } + + /// Dynamically disable the given list of channels + /** + * @param channels The package of channels to disable + */ + void clear_channels(level channels) + { + scoped_lock_type lock(m_lock); + m_dynamic_channels &= ~channels; + } + + /// Write a string message to the given channel + /** + * @param channel The channel to write to + * @param msg The message to write + */ + void write(level channel, std::string const &msg) + { + scoped_lock_type lock(m_lock); + if (!this->dynamic_test(channel)) + { + return; + } + qCDebug(chatterinoWebsocket).nospace() + << names::channel_name(channel) << ": " + << QString::fromStdString(msg); + } + + /// Write a cstring message to the given channel + /** + * @param channel The channel to write to + * @param msg The message to write + */ + void write(level channel, char const *msg) + { + scoped_lock_type lock(m_lock); + if (!this->dynamic_test(channel)) + { + return; + } + qCDebug(chatterinoWebsocket).nospace() + << names::channel_name(channel) << ": " << msg; + } + + /// Test whether a channel is statically enabled + /** + * @param channel The package of channels to test + */ + + _WEBSOCKETPP_CONSTEXPR_TOKEN_ bool static_test(level channel) const + { + return ((channel & m_static_channels) != 0); + } + + /// Test whether a channel is dynamically enabled + /** + * @param channel The package of channels to test + */ + bool dynamic_test(level channel) + { + return ((channel & m_dynamic_channels) != 0); + } + + protected: + typedef typename concurrency::scoped_lock_type scoped_lock_type; + typedef typename concurrency::mutex_type mutex_type; + mutex_type m_lock; + + private: + level const m_static_channels; + level m_dynamic_channels; + }; + +} // namespace log +} // namespace websocketpp + +#endif // CHATTERINOWEBSOCKETPPLOGGER_HPP diff --git a/src/providers/twitch/IrcMessageHandler.cpp b/src/providers/twitch/IrcMessageHandler.cpp index bac05f24b..57f4f90ff 100644 --- a/src/providers/twitch/IrcMessageHandler.cpp +++ b/src/providers/twitch/IrcMessageHandler.cpp @@ -1,6 +1,7 @@ #include "IrcMessageHandler.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "messages/LimitedQueue.hpp" #include "messages/Message.hpp" @@ -361,8 +362,9 @@ void IrcMessageHandler::handleClearChatMessage(Communi::IrcMessage *message) if (chan->isEmpty()) { - qDebug() << "[IrcMessageHandler:handleClearChatMessage] Twitch channel" - << chanName << "not found"; + qCDebug(chatterinoTwitch) + << "[IrcMessageHandler:handleClearChatMessage] Twitch channel" + << chanName << "not found"; return; } @@ -427,9 +429,10 @@ void IrcMessageHandler::handleClearMessageMessage(Communi::IrcMessage *message) if (chan->isEmpty()) { - qDebug() << "[IrcMessageHandler:handleClearMessageMessage] Twitch " - "channel" - << chanName << "not found"; + qCDebug(chatterinoTwitch) + << "[IrcMessageHandler:handleClearMessageMessage] Twitch " + "channel" + << chanName << "not found"; return; } @@ -712,8 +715,9 @@ void IrcMessageHandler::handleNoticeMessage(Communi::IrcNoticeMessage *message) if (channel->isEmpty()) { - qDebug() << "[IrcManager:handleNoticeMessage] Channel" - << channelName << "not found in channel manager"; + qCDebug(chatterinoTwitch) + << "[IrcManager:handleNoticeMessage] Channel" << channelName + << "not found in channel manager"; return; } diff --git a/src/providers/twitch/PubsubClient.cpp b/src/providers/twitch/PubsubClient.cpp index ff60b7781..9ebbd8734 100644 --- a/src/providers/twitch/PubsubClient.cpp +++ b/src/providers/twitch/PubsubClient.cpp @@ -8,7 +8,9 @@ #include #include +#include #include +#include "common/QLogging.hpp" #define TWITCH_PUBSUB_URL "wss://pubsub-edge.twitch.tv" @@ -154,7 +156,8 @@ namespace detail { if (self->awaitingPong_) { - qDebug() << "No pong response, disconnect!"; + qCDebug(chatterinoPubsub) + << "No pong response, disconnect!"; // TODO(pajlada): Label this connection as "disconnect me" } }); @@ -178,8 +181,8 @@ namespace detail { if (ec) { - qDebug() << "Error sending message" << payload << ":" - << ec.message().c_str(); + qCDebug(chatterinoPubsub) << "Error sending message" << payload + << ":" << ec.message().c_str(); // TODO(pajlada): Check which error code happened and maybe // gracefully handle it @@ -193,7 +196,7 @@ namespace detail { PubSub::PubSub() { - qDebug() << "init PubSub"; + qCDebug(chatterinoPubsub) << "init PubSub"; this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) { @@ -221,7 +224,7 @@ PubSub::PubSub() if (!data.HasMember("args")) { - qDebug() << "Missing required args member"; + qCDebug(chatterinoPubsub) << "Missing required args member"; return; } @@ -229,13 +232,14 @@ PubSub::PubSub() if (!args.IsArray()) { - qDebug() << "args member must be an array"; + qCDebug(chatterinoPubsub) << "args member must be an array"; return; } if (args.Size() == 0) { - qDebug() << "Missing duration argument in slowmode on"; + qCDebug(chatterinoPubsub) + << "Missing duration argument in slowmode on"; return; } @@ -243,7 +247,7 @@ PubSub::PubSub() if (!durationArg.IsString()) { - qDebug() << "Duration arg must be a string"; + qCDebug(chatterinoPubsub) << "Duration arg must be a string"; return; } @@ -336,7 +340,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } action.modded = false; @@ -359,16 +364,18 @@ PubSub::PubSub() if (!getTargetUser(data, action.target)) { - qDebug() << "Error parsing moderation action mod: Unable to get " - "target_user_id"; + qCDebug(chatterinoPubsub) + << "Error parsing moderation action mod: Unable to get " + "target_user_id"; return; } // Load target name from message.data.target_user_login if (!getTargetUserName(data, action.target)) { - qDebug() << "Error parsing moderation action mod: Unable to get " - "target_user_name"; + qCDebug(chatterinoPubsub) + << "Error parsing moderation action mod: Unable to get " + "target_user_name"; return; } @@ -416,7 +423,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -453,7 +461,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -484,7 +493,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -515,7 +525,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -567,7 +578,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -596,7 +608,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -625,7 +638,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -654,7 +668,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -684,7 +699,8 @@ PubSub::PubSub() } catch (const std::runtime_error &ex) { - qDebug() << "Error parsing moderation action:" << ex.what(); + qCDebug(chatterinoPubsub) + << "Error parsing moderation action:" << ex.what(); } }; @@ -697,17 +713,20 @@ PubSub::PubSub() this->signals_.moderation.automodUserMessage.invoke(action); }; - this->moderationActionHandlers["denied_automod_message"] = - [](const auto &data, const auto &roomID) { - // This message got denied by a moderator - // qDebug() << QString::fromStdString(rj::stringify(data)); - }; + this->moderationActionHandlers["denied_automod_message"] = [](const auto + &data, + const auto + &roomID) { + // This message got denied by a moderator + // qCDebug(chatterinoPubsub) << QString::fromStdString(rj::stringify(data)); + }; - this->moderationActionHandlers["approved_automod_message"] = - [](const auto &data, const auto &roomID) { - // This message got approved by a moderator - // qDebug() << QString::fromStdString(rj::stringify(data)); - }; + this->moderationActionHandlers + ["approved_automod_message"] = [](const auto &data, + const auto &roomID) { + // This message got approved by a moderator + // qCDebug(chatterinoPubsub) << QString::fromStdString(rj::stringify(data)); + }; this->websocketClient.set_access_channels(websocketpp::log::alevel::all); this->websocketClient.clear_access_channels( @@ -737,7 +756,8 @@ void PubSub::addClient() if (ec) { - qDebug() << "Unable to establish connection:" << ec.message().c_str(); + qCDebug(chatterinoPubsub) + << "Unable to establish connection:" << ec.message().c_str(); return; } @@ -758,7 +778,7 @@ void PubSub::listenToWhispers(std::shared_ptr account) auto userID = account->getUserId(); - qDebug() << "Connection open!"; + qCDebug(chatterinoPubsub) << "Connection open!"; websocketpp::lib::error_code ec; std::vector topics({topicFormat.arg(userID)}); @@ -767,8 +787,9 @@ void PubSub::listenToWhispers(std::shared_ptr account) if (ec) { - qDebug() << "Unable to send message to websocket server:" - << ec.message().c_str(); + qCDebug(chatterinoPubsub) + << "Unable to send message to websocket server:" + << ec.message().c_str(); return; } } @@ -799,7 +820,7 @@ void PubSub::listenToChannelModerationActions( return; } - qDebug() << "Listen to topic" << topic; + qCDebug(chatterinoPubsub) << "Listen to topic" << topic; this->listenToTopic(topic, account); } @@ -818,8 +839,7 @@ void PubSub::listenToChannelPointRewards(const QString &channelID, { return; } - - qDebug() << "Listen to topic" << topic; + qCDebug(chatterinoPubsub) << "Listen to topic" << topic; this->listenToTopic(topic, account); } @@ -884,16 +904,18 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, if (!res) { - qDebug() << "Error parsing message '" << payload.c_str() - << "' from PubSub:" << rapidjson::GetParseError_En(res.Code()); + qCDebug(chatterinoPubsub) + << "Error parsing message '" << payload.c_str() + << "' from PubSub:" << rapidjson::GetParseError_En(res.Code()); return; } if (!msg.IsObject()) { - qDebug() << "Error parsing message '" << payload.c_str() - << "' from PubSub. Root object is not an " - "object"; + qCDebug(chatterinoPubsub) + << "Error parsing message '" << payload.c_str() + << "' from PubSub. Root object is not an " + "object"; return; } @@ -901,7 +923,8 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, if (!rj::getSafe(msg, "type", type)) { - qDebug() << "Missing required string member `type` in message root"; + qCDebug(chatterinoPubsub) + << "Missing required string member `type` in message root"; return; } @@ -913,7 +936,8 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, { if (!msg.HasMember("data")) { - qDebug() << "Missing required object member `data` in message root"; + qCDebug(chatterinoPubsub) + << "Missing required object member `data` in message root"; return; } @@ -921,7 +945,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, if (!data.IsObject()) { - qDebug() << "Member `data` must be an object"; + qCDebug(chatterinoPubsub) << "Member `data` must be an object"; return; } @@ -941,7 +965,7 @@ void PubSub::onMessage(websocketpp::connection_hdl hdl, } else { - qDebug() << "Unknown message type:" << type; + qCDebug(chatterinoPubsub) << "Unknown message type:" << type; } } @@ -1002,7 +1026,8 @@ PubSub::WebsocketContextPtr PubSub::onTLSInit(websocketpp::connection_hdl hdl) } catch (const std::exception &e) { - qDebug() << "Exception caught in OnTLSInit:" << e.what(); + qCDebug(chatterinoPubsub) + << "Exception caught in OnTLSInit:" << e.what(); } return ctx; @@ -1019,12 +1044,14 @@ void PubSub::handleListenResponse(const rapidjson::Document &msg) if (error.isEmpty()) { - qDebug() << "Successfully listened to nonce" << nonce; + qCDebug(chatterinoPubsub) + << "Successfully listened to nonce" << nonce; // Nothing went wrong return; } - qDebug() << "PubSub error:" << error << "on nonce" << nonce; + qCDebug(chatterinoPubsub) + << "PubSub error:" << error << "on nonce" << nonce; return; } } @@ -1035,7 +1062,8 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (!rj::getSafe(outerData, "topic", topic)) { - qDebug() << "Missing required string member `topic` in outerData"; + qCDebug(chatterinoPubsub) + << "Missing required string member `topic` in outerData"; return; } @@ -1043,7 +1071,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (!rj::getSafe(outerData, "message", payload)) { - qDebug() << "Expected string message in outerData"; + qCDebug(chatterinoPubsub) << "Expected string message in outerData"; return; } @@ -1053,8 +1081,9 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (!res) { - qDebug() << "Error parsing message '" << payload.c_str() - << "' from PubSub:" << rapidjson::GetParseError_En(res.Code()); + qCDebug(chatterinoPubsub) + << "Error parsing message '" << payload.c_str() + << "' from PubSub:" << rapidjson::GetParseError_En(res.Code()); return; } @@ -1064,7 +1093,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (!rj::getSafe(msg, "type", whisperType)) { - qDebug() << "Bad whisper data"; + qCDebug(chatterinoPubsub) << "Bad whisper data"; return; } @@ -1082,7 +1111,8 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) } else { - qDebug() << "Invalid whisper type:" << whisperType.c_str(); + qCDebug(chatterinoPubsub) + << "Invalid whisper type:" << whisperType.c_str(); return; } } @@ -1096,8 +1126,8 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (!rj::getSafe(data, "moderation_action", moderationAction)) { - qDebug() << "Missing moderation action in data:" - << rj::stringify(data).c_str(); + qCDebug(chatterinoPubsub) << "Missing moderation action in data:" + << rj::stringify(data).c_str(); return; } @@ -1105,8 +1135,9 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) if (handlerIt == this->moderationActionHandlers.end()) { - qDebug() << "No handler found for moderation action" - << moderationAction.c_str(); + qCDebug(chatterinoPubsub) + << "No handler found for moderation action" + << moderationAction.c_str(); return; } @@ -1118,7 +1149,7 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) std::string pointEventType; if (!rj::getSafe(msg, "type", pointEventType)) { - qDebug() << "Bad channel point event data"; + qCDebug(chatterinoPubsub) << "Bad channel point event data"; return; } @@ -1126,33 +1157,36 @@ void PubSub::handleMessageResponse(const rapidjson::Value &outerData) { if (!rj::getSafeObject(msg, "data", msg)) { - qDebug() << "No data found for redeemed reward"; + qCDebug(chatterinoPubsub) + << "No data found for redeemed reward"; return; } if (!rj::getSafeObject(msg, "redemption", msg)) { - qDebug() << "No redemption info found for redeemed reward"; + qCDebug(chatterinoPubsub) + << "No redemption info found for redeemed reward"; return; } this->signals_.pointReward.redeemed.invoke(msg); } else { - qDebug() << "Invalid point event type:" << pointEventType.c_str(); + qCDebug(chatterinoPubsub) + << "Invalid point event type:" << pointEventType.c_str(); } } else { - qDebug() << "Unknown topic:" << topic; + qCDebug(chatterinoPubsub) << "Unknown topic:" << topic; return; } } void PubSub::runThread() { - qDebug() << "Start pubsub manager thread"; + qCDebug(chatterinoPubsub) << "Start pubsub manager thread"; this->websocketClient.run(); - qDebug() << "Done with pubsub manager thread"; + qCDebug(chatterinoPubsub) << "Done with pubsub manager thread"; } } // namespace chatterino diff --git a/src/providers/twitch/PubsubClient.hpp b/src/providers/twitch/PubsubClient.hpp index 3c76533b3..686098c8a 100644 --- a/src/providers/twitch/PubsubClient.hpp +++ b/src/providers/twitch/PubsubClient.hpp @@ -1,5 +1,6 @@ #pragma once +#include "providers/twitch/ChatterinoWebSocketppLogger.hpp" #include "providers/twitch/PubsubActions.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchIrcServer.hpp" @@ -9,6 +10,8 @@ #include #include #include +#include +#include #include #include @@ -21,8 +24,23 @@ namespace chatterino { -using WebsocketClient = - websocketpp::client; +struct chatterinoconfig : public websocketpp::config::asio_tls_client { + typedef websocketpp::log::chatterinowebsocketpplogger< + concurrency_type, websocketpp::log::elevel> + elog_type; + typedef websocketpp::log::chatterinowebsocketpplogger< + concurrency_type, websocketpp::log::alevel> + alog_type; + + struct permessage_deflate_config { + }; + + typedef websocketpp::extensions::permessage_deflate::disabled< + permessage_deflate_config> + permessage_deflate_type; +}; + +using WebsocketClient = websocketpp::client; using WebsocketHandle = websocketpp::connection_hdl; using WebsocketErrorCode = websocketpp::lib::error_code; diff --git a/src/providers/twitch/PubsubHelpers.hpp b/src/providers/twitch/PubsubHelpers.hpp index d0854af26..3896f07ff 100644 --- a/src/providers/twitch/PubsubHelpers.hpp +++ b/src/providers/twitch/PubsubHelpers.hpp @@ -3,6 +3,7 @@ #include #include #include +#include "common/QLogging.hpp" #include "util/RapidjsonHelpers.hpp" namespace chatterino { @@ -34,7 +35,8 @@ void runAfter(boost::asio::io_service &ioService, Duration duration, timer->async_wait([timer, cb](const boost::system::error_code &ec) { if (ec) { - qDebug() << "Error in runAfter:" << ec.message().c_str(); + qCDebug(chatterinoPubsub) + << "Error in runAfter:" << ec.message().c_str(); return; } @@ -52,7 +54,8 @@ void runAfter(std::shared_ptr timer, timer->async_wait([timer, cb](const boost::system::error_code &ec) { if (ec) { - qDebug() << "Error in runAfter:" << ec.message().c_str(); + qCDebug(chatterinoPubsub) + << "Error in runAfter:" << ec.message().c_str(); return; } diff --git a/src/providers/twitch/TwitchAccount.cpp b/src/providers/twitch/TwitchAccount.cpp index 1270d14b1..90cef379f 100644 --- a/src/providers/twitch/TwitchAccount.cpp +++ b/src/providers/twitch/TwitchAccount.cpp @@ -6,6 +6,7 @@ #include "common/Env.hpp" #include "common/NetworkRequest.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" #include "providers/twitch/TwitchCommon.hpp" #include "providers/twitch/api/Helix.hpp" #include "singletons/Emotes.hpp" @@ -133,8 +134,9 @@ void TwitchAccount::loadIgnores() TwitchUser ignoredUser; if (!rj::getSafe(userIt->value, ignoredUser)) { - qDebug() << "Error parsing twitch user JSON" - << rj::stringify(userIt->value).c_str(); + qCWarning(chatterinoTwitch) + << "Error parsing twitch user JSON" + << rj::stringify(userIt->value).c_str(); continue; } @@ -338,14 +340,15 @@ std::set TwitchAccount::getIgnores() const void TwitchAccount::loadEmotes() { - qDebug() << "Loading Twitch emotes for user" << this->getUserName(); + qCDebug(chatterinoTwitch) + << "Loading Twitch emotes for user" << this->getUserName(); const auto &clientID = this->getOAuthClient(); const auto &oauthToken = this->getOAuthToken(); if (clientID.isEmpty() || oauthToken.isEmpty()) { - qDebug() << "Missing Client ID or OAuth token"; + qCDebug(chatterinoTwitch) << "Missing Client ID or OAuth token"; return; } @@ -356,7 +359,8 @@ void TwitchAccount::loadEmotes() .authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken()) .onError([=](NetworkResult result) { - qDebug() << "[TwitchAccount::loadEmotes] Error" << result.status(); + qCWarning(chatterinoTwitch) + << "[TwitchAccount::loadEmotes] Error" << result.status(); if (result.status() == 203) { // onFinished(FollowResult_NotFollowing); @@ -394,8 +398,8 @@ void TwitchAccount::autoModAllow(const QString msgID) .authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken()) .onError([=](NetworkResult result) { - qDebug() << "[TwitchAccounts::autoModAllow] Error" - << result.status(); + qCWarning(chatterinoTwitch) + << "[TwitchAccounts::autoModAllow] Error" << result.status(); }) .execute(); } @@ -413,8 +417,8 @@ void TwitchAccount::autoModDeny(const QString msgID) .authorizeTwitchV5(this->getOAuthClient(), this->getOAuthToken()) .onError([=](NetworkResult result) { - qDebug() << "[TwitchAccounts::autoModDeny] Error" - << result.status(); + qCWarning(chatterinoTwitch) + << "[TwitchAccounts::autoModDeny] Error" << result.status(); }) .execute(); } @@ -429,7 +433,8 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root) auto emoticonSets = root.FindMember("emoticon_sets"); if (emoticonSets == root.MemberEnd() || !emoticonSets->value.IsObject()) { - qDebug() << "No emoticon_sets in load emotes response"; + qCWarning(chatterinoTwitch) + << "No emoticon_sets in load emotes response"; return; } @@ -445,21 +450,22 @@ void TwitchAccount::parseEmotes(const rapidjson::Document &root) { if (!emoteJSON.IsObject()) { - qDebug() << "Emote value was invalid"; + qCWarning(chatterinoTwitch) << "Emote value was invalid"; return; } uint64_t idNumber; if (!rj::getSafe(emoteJSON, "id", idNumber)) { - qDebug() << "No ID key found in Emote value"; + qCWarning(chatterinoTwitch) << "No ID key found in Emote value"; return; } QString _code; if (!rj::getSafe(emoteJSON, "code", _code)) { - qDebug() << "No code key found in Emote value"; + qCWarning(chatterinoTwitch) + << "No code key found in Emote value"; return; } @@ -486,7 +492,7 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr emoteSet) { if (!emoteSet) { - qDebug() << "null emote set sent"; + qCWarning(chatterinoTwitch) << "null emote set sent"; return; } @@ -502,8 +508,8 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr emoteSet) NetworkRequest(Env::get().twitchEmoteSetResolverUrl.arg(emoteSet->key)) .cache() .onError([](NetworkResult result) { - qDebug() << "Error code" << result.status() - << "while loading emote set data"; + qCWarning(chatterinoTwitch) << "Error code" << result.status() + << "while loading emote set data"; }) .onSuccess([emoteSet](auto result) -> Outcome { auto root = result.parseRapidJson(); @@ -525,7 +531,8 @@ void TwitchAccount::loadEmoteSetData(std::shared_ptr emoteSet) return Failure; } - qDebug() << "Loaded twitch emote set data for" << emoteSet->key; + qCDebug(chatterinoTwitch) + << "Loaded twitch emote set data for" << emoteSet->key; auto name = channelName; name.detach(); diff --git a/src/providers/twitch/TwitchAccountManager.cpp b/src/providers/twitch/TwitchAccountManager.cpp index 1b8374e0b..4766553b2 100644 --- a/src/providers/twitch/TwitchAccountManager.cpp +++ b/src/providers/twitch/TwitchAccountManager.cpp @@ -1,6 +1,7 @@ #include "providers/twitch/TwitchAccountManager.hpp" #include "common/Common.hpp" +#include "common/QLogging.hpp" #include "providers/twitch/TwitchAccount.hpp" #include "providers/twitch/TwitchCommon.hpp" #include "providers/twitch/api/Helix.hpp" @@ -105,23 +106,26 @@ void TwitchAccountManager::reloadUsers() switch (this->addUser(userData)) { case AddUserResponse::UserAlreadyExists: { - qDebug() << "User" << userData.username << "already exists"; + qCDebug(chatterinoTwitch) + << "User" << userData.username << "already exists"; // Do nothing } break; case AddUserResponse::UserValuesUpdated: { - qDebug() << "User" << userData.username - << "already exists, and values updated!"; + qCDebug(chatterinoTwitch) + << "User" << userData.username + << "already exists, and values updated!"; if (userData.username == this->getCurrent()->getUserName()) { - qDebug() << "It was the current user, so we need to " - "reconnect stuff!"; + qCDebug(chatterinoTwitch) + << "It was the current user, so we need to " + "reconnect stuff!"; this->currentUserChanged.invoke(); } } break; case AddUserResponse::UserAdded: { - qDebug() << "Added user" << userData.username; + qCDebug(chatterinoTwitch) << "Added user" << userData.username; listUpdated = true; } break; @@ -142,14 +146,15 @@ void TwitchAccountManager::load() auto user = this->findUserByUsername(newUsername); if (user) { - qDebug() << "Twitch user updated to" << newUsername; + qCDebug(chatterinoTwitch) + << "Twitch user updated to" << newUsername; getHelix()->update(user->getOAuthClient(), user->getOAuthToken()); getKraken()->update(user->getOAuthClient(), user->getOAuthToken()); this->currentUser_ = user; } else { - qDebug() << "Twitch user updated to anonymous"; + qCDebug(chatterinoTwitch) << "Twitch user updated to anonymous"; this->currentUser_ = this->anonymousUser_; } diff --git a/src/providers/twitch/TwitchChannel.cpp b/src/providers/twitch/TwitchChannel.cpp index 128cfbb4a..7515d86a3 100644 --- a/src/providers/twitch/TwitchChannel.cpp +++ b/src/providers/twitch/TwitchChannel.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace chatterino { namespace { @@ -148,7 +149,7 @@ TwitchChannel::TwitchChannel(const QString &name, , mod_(false) , titleRefreshedTime_(QTime::currentTime().addSecs(-TITLE_REFRESH_PERIOD)) { - qDebug() << "[TwitchChannel" << name << "] Opened"; + qCDebug(chatterinoTwitch) << "[TwitchChannel" << name << "] Opened"; this->liveStatusChanged.connect([this]() { if (this->isLive() == 1) @@ -305,8 +306,8 @@ void TwitchChannel::sendMessage(const QString &message) return; } - qDebug() << "[TwitchChannel" << this->getName() - << "] Send message:" << message; + qCDebug(chatterinoTwitch) + << "[TwitchChannel" << this->getName() << "] Send message:" << message; // Do last message processing QString parsedMessage = app->emotes->emojis.replaceShortCodes(message); @@ -334,7 +335,7 @@ void TwitchChannel::sendMessage(const QString &message) if (messageSent) { - qDebug() << "sent"; + qCDebug(chatterinoTwitch) << "sent"; this->lastSentMessage_ = parsedMessage; } } @@ -593,8 +594,8 @@ void TwitchChannel::refreshLiveStatus() if (roomID.isEmpty()) { - qDebug() << "[TwitchChannel" << this->getName() - << "] Refreshing live status (Missing ID)"; + qCDebug(chatterinoTwitch) << "[TwitchChannel" << this->getName() + << "] Refreshing live status (Missing ID)"; this->setLive(false); return; } @@ -908,7 +909,8 @@ boost::optional TwitchChannel::cheerEmote(const QString &string) int bitAmount = amount.toInt(&ok); if (!ok) { - qDebug() << "Error parsing bit amount in cheerEmote"; + qCDebug(chatterinoTwitch) + << "Error parsing bit amount in cheerEmote"; } for (const auto &emote : set.cheerEmotes) { diff --git a/src/providers/twitch/TwitchHelpers.cpp b/src/providers/twitch/TwitchHelpers.cpp index 5c71c4cd2..e5fdddfef 100644 --- a/src/providers/twitch/TwitchHelpers.cpp +++ b/src/providers/twitch/TwitchHelpers.cpp @@ -1,4 +1,5 @@ #include "providers/twitch/TwitchHelpers.hpp" +#include "common/QLogging.hpp" namespace chatterino { @@ -6,7 +7,7 @@ bool trimChannelName(const QString &channelName, QString &outChannelName) { if (channelName.length() < 2) { - qDebug() << "channel name length below 2"; + qCDebug(chatterinoTwitch) << "channel name length below 2"; return false; } diff --git a/src/providers/twitch/TwitchIrcServer.cpp b/src/providers/twitch/TwitchIrcServer.cpp index 29c1c87e1..f060b15af 100644 --- a/src/providers/twitch/TwitchIrcServer.cpp +++ b/src/providers/twitch/TwitchIrcServer.cpp @@ -6,6 +6,7 @@ #include "Application.hpp" #include "common/Common.hpp" #include "common/Env.hpp" +#include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "messages/Message.hpp" #include "messages/MessageBuilder.hpp" @@ -55,7 +56,7 @@ void TwitchIrcServer::initializeConnection(IrcConnection *connection, std::shared_ptr account = getApp()->accounts->twitch.getCurrent(); - qDebug() << "logging in as" << account->getUserName(); + qCDebug(chatterinoTwitch) << "logging in as" << account->getUserName(); QString username = account->getUserName(); QString oauthToken = account->getOAuthToken(); diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 98d1de23c..ec93e8bc3 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "common/QLogging.hpp" namespace { @@ -712,7 +713,8 @@ void TwitchMessageBuilder::runIgnoreReplaces( { if ((*copy).ptr == nullptr) { - qDebug() << "remem nullptr" << (*copy).name.string; + qCDebug(chatterinoTwitch) + << "remem nullptr" << (*copy).name.string; } } std::vector v(it, twitchEmotes.end()); @@ -749,7 +751,8 @@ void TwitchMessageBuilder::runIgnoreReplaces( { if (emote.second == nullptr) { - qDebug() << "emote null" << emote.first.string; + qCDebug(chatterinoTwitch) + << "emote null" << emote.first.string; } twitchEmotes.push_back(TwitchEmoteOccurence{ startIndex + pos, @@ -821,7 +824,8 @@ void TwitchMessageBuilder::runIgnoreReplaces( { if (tup.ptr == nullptr) { - qDebug() << "v nullptr" << tup.name.string; + qCDebug(chatterinoTwitch) + << "v nullptr" << tup.name.string; continue; } QRegularExpression emoteregex( @@ -885,7 +889,8 @@ void TwitchMessageBuilder::runIgnoreReplaces( { if (tup.ptr == nullptr) { - qDebug() << "v nullptr" << tup.name.string; + qCDebug(chatterinoTwitch) + << "v nullptr" << tup.name.string; continue; } QRegularExpression emoteregex( @@ -955,7 +960,8 @@ void TwitchMessageBuilder::appendTwitchEmote( start, end, app->emotes->twitch.getOrCreateEmote(id, name), name}; if (emoteOccurence.ptr == nullptr) { - qDebug() << "nullptr" << emoteOccurence.name.string; + qCDebug(chatterinoTwitch) + << "nullptr" << emoteOccurence.name.string; } vec.push_back(std::move(emoteOccurence)); } diff --git a/src/providers/twitch/api/Helix.cpp b/src/providers/twitch/api/Helix.cpp index 73c2923ca..9a42851c3 100644 --- a/src/providers/twitch/api/Helix.cpp +++ b/src/providers/twitch/api/Helix.cpp @@ -1,6 +1,7 @@ #include "providers/twitch/api/Helix.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" namespace chatterino { @@ -320,14 +321,14 @@ NetworkRequest Helix::makeRequest(QString url, QUrlQuery urlQuery) if (this->clientId.isEmpty()) { - qDebug() + qCDebug(chatterinoTwitch) << "Helix::makeRequest called without a client ID set BabyRage"; // return boost::none; } if (this->oauthToken.isEmpty()) { - qDebug() + qCDebug(chatterinoTwitch) << "Helix::makeRequest called without an oauth token set BabyRage"; // return boost::none; } diff --git a/src/providers/twitch/api/Kraken.cpp b/src/providers/twitch/api/Kraken.cpp index be7e98b36..aed7c8c6d 100644 --- a/src/providers/twitch/api/Kraken.cpp +++ b/src/providers/twitch/api/Kraken.cpp @@ -1,6 +1,7 @@ #include "providers/twitch/api/Kraken.hpp" #include "common/Outcome.hpp" +#include "common/QLogging.hpp" #include "providers/twitch/TwitchCommon.hpp" namespace chatterino { @@ -54,7 +55,7 @@ NetworkRequest Kraken::makeRequest(QString url, QUrlQuery urlQuery) if (this->clientId.isEmpty()) { - qDebug() + qCDebug(chatterinoTwitch) << "Kraken::makeRequest called without a client ID set BabyRage"; } diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 94700257f..c711e4be7 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -1,6 +1,7 @@ #include "singletons/NativeMessaging.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "singletons/Paths.hpp" #include "util/PostToThread.hpp" @@ -125,7 +126,7 @@ void NativeMessagingClient::sendMessage(const QByteArray &array) } catch (ipc::interprocess_exception &ex) { - qDebug() << "send to gui process:" << ex.what(); + qCDebug(chatterinoNativeMessage) << "send to gui process:" << ex.what(); } } @@ -169,7 +170,8 @@ void NativeMessagingServer::ReceiverThread::run() } catch (ipc::interprocess_exception &ex) { - qDebug() << "received from gui process:" << ex.what(); + qCDebug(chatterinoNativeMessage) + << "received from gui process:" << ex.what(); } } } @@ -183,7 +185,7 @@ void NativeMessagingServer::ReceiverThread::handleMessage( if (action.isNull()) { - qDebug() << "NM action was null"; + qCDebug(chatterinoNativeMessage) << "NM action was null"; return; } @@ -203,11 +205,13 @@ void NativeMessagingServer::ReceiverThread::handleMessage( args.height = root.value("size").toObject().value("height").toInt(-1); args.fullscreen = attachFullscreen; - qDebug() << args.x << args.width << args.height << args.winId; + qCDebug(chatterinoNativeMessage) + << args.x << args.width << args.height << args.winId; if (_type.isNull() || args.winId.isNull()) { - qDebug() << "NM type, name or winId missing"; + qCDebug(chatterinoNativeMessage) + << "NM type, name or winId missing"; attach = false; attachFullscreen = false; return; @@ -242,7 +246,7 @@ void NativeMessagingServer::ReceiverThread::handleMessage( } else { - qDebug() << "NM unknown channel type"; + qCDebug(chatterinoNativeMessage) << "NM unknown channel type"; } } else if (action == "detach") @@ -251,20 +255,20 @@ void NativeMessagingServer::ReceiverThread::handleMessage( if (winId.isNull()) { - qDebug() << "NM winId missing"; + qCDebug(chatterinoNativeMessage) << "NM winId missing"; return; } #ifdef USEWINSDK postToThread([winId] { - qDebug() << "NW detach"; + qCDebug(chatterinoNativeMessage) << "NW detach"; AttachedWindow::detach(winId); }); #endif } else { - qDebug() << "NM unknown action " + action; + qCDebug(chatterinoNativeMessage) << "NM unknown action " + action; } } diff --git a/src/singletons/Updates.cpp b/src/singletons/Updates.cpp index c7026436c..75e9275e1 100644 --- a/src/singletons/Updates.cpp +++ b/src/singletons/Updates.cpp @@ -9,11 +9,11 @@ #include "util/CombinePath.hpp" #include "util/PostToThread.hpp" -#include #include #include #include #include +#include "common/QLogging.hpp" namespace chatterino { namespace { @@ -59,7 +59,7 @@ Updates::Updates() : currentVersion_(CHATTERINO_VERSION) , updateGuideLink_("https://chatterino.com") { - qDebug() << "init UpdateManager"; + qCDebug(chatterinoUpdate) << "init UpdateManager"; } Updates &Updates::instance() @@ -234,7 +234,7 @@ void Updates::checkForUpdates() { if (!Version::instance().isSupportedOS()) { - qDebug() + qCDebug(chatterinoUpdate) << "Update checking disabled because OS doesn't appear to be one " "of Windows, GNU/Linux or macOS."; return; @@ -260,7 +260,7 @@ void Updates::checkForUpdates() if (!version_val.isString()) { this->setStatus_(SearchFailed); - qDebug() << "error updating"; + qCDebug(chatterinoUpdate) << "error updating"; return Failure; } @@ -270,7 +270,7 @@ void Updates::checkForUpdates() if (!updateExe_val.isString()) { this->setStatus_(SearchFailed); - qDebug() << "error updating"; + qCDebug(chatterinoUpdate) << "error updating"; return Failure; } this->updateExe_ = updateExe_val.toString(); @@ -281,7 +281,7 @@ void Updates::checkForUpdates() if (!portable_val.isString()) { this->setStatus_(SearchFailed); - qDebug() << "error updating"; + qCDebug(chatterinoUpdate) << "error updating"; return Failure; } this->updatePortable_ = portable_val.toString(); diff --git a/src/singletons/WindowManager.cpp b/src/singletons/WindowManager.cpp index cb69e5abe..f44949af5 100644 --- a/src/singletons/WindowManager.cpp +++ b/src/singletons/WindowManager.cpp @@ -13,6 +13,7 @@ #include "Application.hpp" #include "common/Args.hpp" +#include "common/QLogging.hpp" #include "debug/AssertInGuiThread.hpp" #include "messages/MessageElement.hpp" #include "providers/irc/Irc2.hpp" @@ -85,7 +86,7 @@ WindowManager::WindowManager() : windowLayoutFilePath( combinePath(getPaths()->settingsDirectory, WINDOW_LAYOUT_FILENAME)) { - qDebug() << "init WindowManager"; + qCDebug(chatterinoWindowmanager) << "init WindowManager"; auto settings = getSettings(); @@ -270,7 +271,7 @@ Window *WindowManager::windowAt(int index) { return nullptr; } - qDebug() << "getting window at bad index" << index; + qCDebug(chatterinoWindowmanager) << "getting window at bad index" << index; return this->windows_.at(index); } @@ -343,7 +344,7 @@ void WindowManager::save() { return; } - qDebug() << "[WindowManager] Saving"; + qCDebug(chatterinoWindowmanager) << "[WindowManager] Saving"; assertInGuiThread(); QJsonDocument document; diff --git a/src/singletons/helper/LoggingChannel.cpp b/src/singletons/helper/LoggingChannel.cpp index 57b7dd590..112270ca7 100644 --- a/src/singletons/helper/LoggingChannel.cpp +++ b/src/singletons/helper/LoggingChannel.cpp @@ -1,6 +1,7 @@ #include "LoggingChannel.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "singletons/Paths.hpp" #include "singletons/Settings.hpp" @@ -63,13 +64,13 @@ void LoggingChannel::openLogFile() if (!QDir().mkpath(directory)) { - qDebug() << "Unable to create logging path"; + qCDebug(chatterinoHelper) << "Unable to create logging path"; return; } // Open file handle to log file of current date QString fileName = directory + QDir::separator() + baseFileName; - qDebug() << "Logging to" << fileName; + qCDebug(chatterinoHelper) << "Logging to" << fileName; this->fileHandle.setFileName(fileName); this->fileHandle.open(QIODevice::Append); diff --git a/src/util/NuulsUploader.cpp b/src/util/NuulsUploader.cpp index 997e354b4..38a2ee8d3 100644 --- a/src/util/NuulsUploader.cpp +++ b/src/util/NuulsUploader.cpp @@ -14,6 +14,7 @@ #include #include #include +#include "common/QLogging.hpp" #define UPLOAD_DELAY 2000 // Delay between uploads in milliseconds @@ -160,7 +161,7 @@ void uploadImageToNuuls(RawImageData imageData, ChannelPtr channel, ? "" : getLinkFromResponse( result, getSettings()->imageUploaderDeletionLink); - qDebug() << link << deletionLink; + qCDebug(chatterinoNuulsuploader) << link << deletionLink; textEdit.insertPlainText(link + " "); if (uploadQueue.empty()) { diff --git a/src/util/StreamLink.cpp b/src/util/StreamLink.cpp index df582442f..7f3d873d4 100644 --- a/src/util/StreamLink.cpp +++ b/src/util/StreamLink.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "common/QLogging.hpp" #include @@ -92,7 +93,7 @@ namespace { } else { - qDebug() << "Error occured" << err; + qCWarning(chatterinoStreamlink) << "Error occured" << err; } p->deleteLater(); @@ -119,7 +120,7 @@ void getStreamQualities(const QString &channelURL, [=](int res) { if (res != 0) { - qDebug() << "Got error code" << res; + qCWarning(chatterinoStreamlink) << "Got error code" << res; // return; } QString lastLine = QString(p->readAllStandardOutput()); diff --git a/src/widgets/AttachedWindow.cpp b/src/widgets/AttachedWindow.cpp index 115c24375..f1f4ea6df 100644 --- a/src/widgets/AttachedWindow.cpp +++ b/src/widgets/AttachedWindow.cpp @@ -7,6 +7,7 @@ #include #include +#include "common/QLogging.hpp" #ifdef USEWINSDK # include "util/WindowsHelper.hpp" @@ -192,7 +193,8 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr) !qfilename.endsWith("brave.exe")) { - qDebug() << "NM Illegal caller" << qfilename; + qCWarning(chatterinoWidget) + << "NM Illegal caller" << qfilename; this->timer_.stop(); this->deleteLater(); return; @@ -241,7 +243,7 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr) if (::GetLastError() != 0) { - qDebug() << "NM GetLastError()" << ::GetLastError(); + qCWarning(chatterinoWidget) << "NM GetLastError()" << ::GetLastError(); this->timer_.stop(); this->deleteLater(); diff --git a/src/widgets/Notebook.cpp b/src/widgets/Notebook.cpp index 8c1caa0f7..999487f1a 100644 --- a/src/widgets/Notebook.cpp +++ b/src/widgets/Notebook.cpp @@ -1,6 +1,7 @@ #include "widgets/Notebook.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" @@ -153,7 +154,7 @@ void Notebook::select(QWidget *page) } else { - qDebug() + qCDebug(chatterinoWidget) << "Notebook: selected child of page doesn't exist anymore"; } } diff --git a/src/widgets/Scrollbar.cpp b/src/widgets/Scrollbar.cpp index dcf9c3c08..399329b94 100644 --- a/src/widgets/Scrollbar.cpp +++ b/src/widgets/Scrollbar.cpp @@ -1,6 +1,7 @@ #include "widgets/Scrollbar.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "singletons/Settings.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" @@ -228,11 +229,12 @@ void Scrollbar::setCurrentValue(qreal value) void Scrollbar::printCurrentState(const QString &prefix) const { - qDebug() << prefix // - << "Current value: " << this->getCurrentValue() // - << ". Maximum: " << this->getMaximum() // - << ". Minimum: " << this->getMinimum() // - << ". Large change: " << this->getLargeChange(); // + qCDebug(chatterinoWidget) + << prefix // + << "Current value: " << this->getCurrentValue() // + << ". Maximum: " << this->getMaximum() // + << ". Minimum: " << this->getMinimum() // + << ". Large change: " << this->getLargeChange(); // } void Scrollbar::paintEvent(QPaintEvent *) diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index 82737d8a6..9d583942f 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -3,6 +3,7 @@ #include "Application.hpp" #include "common/Common.hpp" #include "common/NetworkRequest.hpp" +#include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "util/Helpers.hpp" @@ -108,11 +109,11 @@ BasicLoginWidget::BasicLoginWidget() this->ui_.layout.addWidget(&this->ui_.unableToOpenBrowserHelper); connect(&this->ui_.loginButton, &QPushButton::clicked, [this, logInLink]() { - qDebug() << "open login in browser"; + qCDebug(chatterinoWidget) << "open login in browser"; auto res = QDesktopServices::openUrl(QUrl(logInLink)); if (!res) { - qDebug() << "open login in browser failed"; + qCWarning(chatterinoWidget) << "open login in browser failed"; this->ui_.unableToOpenBrowserHelper.show(); } }); @@ -152,7 +153,7 @@ BasicLoginWidget::BasicLoginWidget() } else { - qDebug() << "Unknown key in code: " << key; + qCWarning(chatterinoWidget) << "Unknown key in code: " << key; } } diff --git a/src/widgets/dialogs/QualityPopup.cpp b/src/widgets/dialogs/QualityPopup.cpp index 134913752..414ab2548 100644 --- a/src/widgets/dialogs/QualityPopup.cpp +++ b/src/widgets/dialogs/QualityPopup.cpp @@ -1,5 +1,6 @@ #include "QualityPopup.hpp" #include "Application.hpp" +#include "common/QLogging.hpp" #include "singletons/WindowManager.hpp" #include "util/StreamLink.hpp" #include "widgets/Window.hpp" @@ -55,7 +56,8 @@ void QualityPopup::okButtonClicked() } catch (const Exception &ex) { - qDebug() << "Exception caught trying to open streamlink:" << ex.what(); + qCWarning(chatterinoWidget) + << "Exception caught trying to open streamlink:" << ex.what(); } this->close(); diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index e97391581..014f0c773 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -15,6 +15,7 @@ #include "Application.hpp" #include "common/Common.hpp" +#include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "controllers/commands/CommandController.hpp" #include "debug/Benchmark.hpp" @@ -892,8 +893,9 @@ void ChannelView::messageReplaced(size_t index, MessagePtr &replacement) auto snapshot = this->messages_.getSnapshot(); if (index >= snapshot.size()) { - qDebug() << "Tried to replace out of bounds message. Index:" << index - << ". Length:" << snapshot.size(); + qCDebug(chatterinoWidget) + << "Tried to replace out of bounds message. Index:" << index + << ". Length:" << snapshot.size(); return; } diff --git a/src/widgets/settingspages/AboutPage.cpp b/src/widgets/settingspages/AboutPage.cpp index b802f256a..8d002b9e4 100644 --- a/src/widgets/settingspages/AboutPage.cpp +++ b/src/widgets/settingspages/AboutPage.cpp @@ -1,6 +1,7 @@ #include "AboutPage.hpp" #include "common/Modes.hpp" +#include "common/QLogging.hpp" #include "common/Version.hpp" #include "util/LayoutCreator.hpp" #include "util/RemoveScrollAreaBackground.hpp" @@ -166,7 +167,8 @@ AboutPage::AboutPage() if (contributorParts.size() != 4) { - qDebug() << "Missing parts in line" << line; + qCDebug(chatterinoWidget) + << "Missing parts in line" << line; continue; } diff --git a/src/widgets/settingspages/GeneralPageView.hpp b/src/widgets/settingspages/GeneralPageView.hpp index 4e4ad3e58..4be8f8c2a 100644 --- a/src/widgets/settingspages/GeneralPageView.hpp +++ b/src/widgets/settingspages/GeneralPageView.hpp @@ -4,6 +4,7 @@ #include #include "Application.hpp" #include "common/ChatterinoSetting.hpp" +#include "common/QLogging.hpp" #include "singletons/WindowManager.hpp" #include "widgets/helper/SignalLabel.hpp" @@ -190,7 +191,7 @@ public: protected: void resizeEvent(QResizeEvent *ev) override { - qDebug() << ev->size(); + qCDebug(chatterinoWidget) << ev->size(); } private: diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 6c8ce3f89..fa0174be9 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -4,6 +4,7 @@ #include "common/Common.hpp" #include "common/Env.hpp" #include "common/NetworkRequest.hpp" +#include "common/QLogging.hpp" #include "controllers/accounts/AccountController.hpp" #include "providers/twitch/EmoteValue.hpp" #include "providers/twitch/TwitchChannel.hpp" @@ -639,7 +640,8 @@ void Split::openInStreamlink() } catch (const Exception &ex) { - qDebug() << "Error in doOpenStreamlink:" << ex.what(); + qCWarning(chatterinoWidget) + << "Error in doOpenStreamlink:" << ex.what(); } }