Add logging to experimental IRC (#2996)

Co-authored-by: xHeaveny <69117321+xHeaveny@users.noreply.github.com>
Co-authored-by: pajlada <rasmus.karlsson@pajlada.com>
This commit is contained in:
Mm2PL 2022-07-02 09:42:28 +00:00 committed by GitHub
parent 0ab53d62ea
commit bbadbc4b33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 17 deletions

View file

@ -84,6 +84,7 @@
- Minor: Made join and part message have links to usercards. (#3358) - Minor: Made join and part message have links to usercards. (#3358)
- Minor: Show picked outcome in prediction badges. (#3357) - Minor: Show picked outcome in prediction badges. (#3357)
- Minor: Add support for Emoji in IRC (#3354) - Minor: Add support for Emoji in IRC (#3354)
- Minor: Added logging to experimental IRC (#2996)
- Minor: Moved `/live` logs to its own subdirectory. (Logs from before this change will still be available in `Channels -> live`). (#3393) - Minor: Moved `/live` logs to its own subdirectory. (Logs from before this change will still be available in `Channels -> live`). (#3393)
- Minor: Added clear button to settings search bar. (#3403) - Minor: Added clear button to settings search bar. (#3403)
- Minor: Added autocompletion for default Twitch commands starting with the dot (e.g. `.mods` which does the same as `/mods`). (#3144) - Minor: Added autocompletion for default Twitch commands starting with the dot (e.g. `.mods` which does the same as `/mods`). (#3144)

View file

@ -3,6 +3,8 @@
#include "Application.hpp" #include "Application.hpp"
#include "messages/Message.hpp" #include "messages/Message.hpp"
#include "messages/MessageBuilder.hpp" #include "messages/MessageBuilder.hpp"
#include "providers/irc/IrcChannel2.hpp"
#include "providers/irc/IrcServer.hpp"
#include "providers/twitch/IrcMessageHandler.hpp" #include "providers/twitch/IrcMessageHandler.hpp"
#include "singletons/Emotes.hpp" #include "singletons/Emotes.hpp"
#include "singletons/Logging.hpp" #include "singletons/Logging.hpp"
@ -81,11 +83,20 @@ void Channel::addMessage(MessagePtr message,
auto app = getApp(); auto app = getApp();
MessagePtr deleted; MessagePtr deleted;
// FOURTF: change this when adding more providers if (!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog))
if (this->isTwitchChannel() &&
(!overridingFlags || !overridingFlags->has(MessageFlag::DoNotLog)))
{ {
app->logging->addMessage(this->name_, message); QString channelPlatform("other");
if (this->type_ == Type::Irc)
{
auto irc = static_cast<IrcChannel *>(this);
channelPlatform =
QString("irc-%1").arg(irc->server()->userFriendlyIdentifier());
}
else if (this->isTwitchChannel())
{
channelPlatform = "twitch";
}
app->logging->addMessage(this->name_, message, channelPlatform);
} }
if (this->messages_.pushBack(message, deleted)) if (this->messages_.pushBack(message, deleted))

View file

@ -58,6 +58,11 @@ const QString &IrcServer::nick()
return this->data_->nick.isEmpty() ? this->data_->user : this->data_->nick; return this->data_->nick.isEmpty() ? this->data_->user : this->data_->nick;
} }
const QString &IrcServer::userFriendlyIdentifier()
{
return this->data_->host;
}
void IrcServer::initializeConnectionSignals(IrcConnection *connection, void IrcServer::initializeConnectionSignals(IrcConnection *connection,
ConnectionType type) ConnectionType type)
{ {

View file

@ -18,6 +18,7 @@ public:
int id(); int id();
const QString &user(); const QString &user();
const QString &nick(); const QString &nick();
const QString &userFriendlyIdentifier();
// AbstractIrcServer interface // AbstractIrcServer interface
protected: protected:

View file

@ -3,11 +3,14 @@
#include "Application.hpp" #include "Application.hpp"
#include "singletons/Paths.hpp" #include "singletons/Paths.hpp"
#include "singletons/Settings.hpp" #include "singletons/Settings.hpp"
#include "singletons/helper/LoggingChannel.hpp"
#include <QDir> #include <QDir>
#include <QStandardPaths> #include <QStandardPaths>
#include <memory>
#include <unordered_map> #include <unordered_map>
#include <utility>
namespace chatterino { namespace chatterino {
@ -15,24 +18,35 @@ void Logging::initialize(Settings &settings, Paths &paths)
{ {
} }
void Logging::addMessage(const QString &channelName, MessagePtr message) void Logging::addMessage(const QString &channelName, MessagePtr message,
const QString &platformName)
{ {
if (!getSettings()->enableLogging) if (!getSettings()->enableLogging)
{ {
return; return;
} }
auto it = this->loggingChannels_.find(channelName); auto platIt = this->loggingChannels_.find(platformName);
if (it == this->loggingChannels_.end()) if (platIt == this->loggingChannels_.end())
{ {
auto channel = new LoggingChannel(channelName); auto channel = new LoggingChannel(channelName, platformName);
channel->addMessage(message); channel->addMessage(message);
this->loggingChannels_.emplace( auto map = std::map<QString, std::unique_ptr<LoggingChannel>>();
channelName, std::unique_ptr<LoggingChannel>(std::move(channel))); this->loggingChannels_[platformName] = std::move(map);
auto &ref = this->loggingChannels_.at(platformName);
ref.emplace(channelName, std::move(channel));
return;
}
auto chanIt = platIt->second.find(channelName);
if (chanIt == platIt->second.end())
{
auto channel = new LoggingChannel(channelName, platformName);
channel->addMessage(message);
platIt->second.emplace(channelName, std::move(channel));
} }
else else
{ {
it->second->addMessage(message); chanIt->second->addMessage(message);
} }
} }

View file

@ -20,10 +20,15 @@ public:
virtual void initialize(Settings &settings, Paths &paths) override; virtual void initialize(Settings &settings, Paths &paths) override;
void addMessage(const QString &channelName, MessagePtr message); void addMessage(const QString &channelName, MessagePtr message,
const QString &platformName);
private: private:
std::map<QString, std::unique_ptr<LoggingChannel>> loggingChannels_; using PlatformName = QString;
using ChannelName = QString;
std::map<PlatformName,
std::map<ChannelName, std::unique_ptr<LoggingChannel>>>
loggingChannels_;
}; };
} // namespace chatterino } // namespace chatterino

View file

@ -13,8 +13,10 @@ namespace chatterino {
QByteArray endline("\n"); QByteArray endline("\n");
LoggingChannel::LoggingChannel(const QString &_channelName) LoggingChannel::LoggingChannel(const QString &_channelName,
const QString &_platform)
: channelName(_channelName) : channelName(_channelName)
, platform(_platform)
{ {
if (this->channelName.startsWith("/whispers")) if (this->channelName.startsWith("/whispers"))
{ {
@ -34,8 +36,9 @@ LoggingChannel::LoggingChannel(const QString &_channelName)
QStringLiteral("Channels") + QDir::separator() + channelName; QStringLiteral("Channels") + QDir::separator() + channelName;
} }
// FOURTF: change this when adding more providers // enforce capitalized platform names
this->subDirectory = "Twitch/" + this->subDirectory; this->subDirectory = platform[0].toUpper() + platform.mid(1).toLower() +
QDir::separator() + this->subDirectory;
getSettings()->logPath.connect([this](const QString &logPath, auto) { getSettings()->logPath.connect([this](const QString &logPath, auto) {
this->baseDirectory = this->baseDirectory =

View file

@ -15,7 +15,8 @@ class Logging;
class LoggingChannel : boost::noncopyable class LoggingChannel : boost::noncopyable
{ {
explicit LoggingChannel(const QString &_channelName); explicit LoggingChannel(const QString &_channelName,
const QString &platform);
public: public:
~LoggingChannel(); ~LoggingChannel();
@ -34,6 +35,7 @@ private:
QString generateDateString(const QDateTime &now); QString generateDateString(const QDateTime &now);
const QString channelName; const QString channelName;
const QString platform;
QString baseDirectory; QString baseDirectory;
QString subDirectory; QString subDirectory;