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
8 changed files with 59 additions and 17 deletions
+21 -7
View File
@@ -3,11 +3,14 @@
#include "Application.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
#include "singletons/helper/LoggingChannel.hpp"
#include <QDir>
#include <QStandardPaths>
#include <memory>
#include <unordered_map>
#include <utility>
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)
{
return;
}
auto it = this->loggingChannels_.find(channelName);
if (it == this->loggingChannels_.end())
auto platIt = this->loggingChannels_.find(platformName);
if (platIt == this->loggingChannels_.end())
{
auto channel = new LoggingChannel(channelName);
auto channel = new LoggingChannel(channelName, platformName);
channel->addMessage(message);
this->loggingChannels_.emplace(
channelName, std::unique_ptr<LoggingChannel>(std::move(channel)));
auto map = std::map<QString, std::unique_ptr<LoggingChannel>>();
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
{
it->second->addMessage(message);
chanIt->second->addMessage(message);
}
}
+7 -2
View File
@@ -20,10 +20,15 @@ public:
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:
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
+6 -3
View File
@@ -13,8 +13,10 @@ namespace chatterino {
QByteArray endline("\n");
LoggingChannel::LoggingChannel(const QString &_channelName)
LoggingChannel::LoggingChannel(const QString &_channelName,
const QString &_platform)
: channelName(_channelName)
, platform(_platform)
{
if (this->channelName.startsWith("/whispers"))
{
@@ -34,8 +36,9 @@ LoggingChannel::LoggingChannel(const QString &_channelName)
QStringLiteral("Channels") + QDir::separator() + channelName;
}
// FOURTF: change this when adding more providers
this->subDirectory = "Twitch/" + this->subDirectory;
// enforce capitalized platform names
this->subDirectory = platform[0].toUpper() + platform.mid(1).toLower() +
QDir::separator() + this->subDirectory;
getSettings()->logPath.connect([this](const QString &logPath, auto) {
this->baseDirectory =
+3 -1
View File
@@ -15,7 +15,8 @@ class Logging;
class LoggingChannel : boost::noncopyable
{
explicit LoggingChannel(const QString &_channelName);
explicit LoggingChannel(const QString &_channelName,
const QString &platform);
public:
~LoggingChannel();
@@ -34,6 +35,7 @@ private:
QString generateDateString(const QDateTime &now);
const QString channelName;
const QString platform;
QString baseDirectory;
QString subDirectory;