2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Logging.hpp"
|
2018-04-27 22:11:19 +02:00
|
|
|
|
Sort and force grouping of includes (#4172)
This change enforces strict include grouping using IncludeCategories
In addition to adding this to the .clang-format file and applying it in the tests/src and src directories, I also did the following small changes:
In ChatterSet.hpp, I changed lrucache to a <>include
In Irc2.hpp, I change common/SignalVector.hpp to a "project-include"
In AttachedWindow.cpp, NativeMessaging.cpp, WindowsHelper.hpp, BaseWindow.cpp, and StreamerMode.cpp, I disabled clang-format for the windows-includes
In WindowDescriptors.hpp, I added the missing vector include. It was previously not needed because the include was handled by another file that was previously included first.
clang-format minimum version has been bumped, so Ubuntu version used in the check-formatting job has been bumped to 22.04 (which is the latest LTS)
2022-11-27 19:32:53 +01:00
|
|
|
#include "singletons/helper/LoggingChannel.hpp"
|
2018-06-28 19:46:45 +02:00
|
|
|
#include "singletons/Paths.hpp"
|
|
|
|
#include "singletons/Settings.hpp"
|
2018-01-28 14:23:55 +01:00
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
|
2022-07-02 11:42:28 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
2018-01-28 14:23:55 +01:00
|
|
|
|
|
|
|
namespace chatterino {
|
|
|
|
|
2023-01-15 12:47:22 +01:00
|
|
|
void Logging::initialize(Settings &settings, Paths & /*paths*/)
|
2018-01-28 14:23:55 +01:00
|
|
|
{
|
2023-01-15 12:47:22 +01:00
|
|
|
settings.loggedChannels.delayedItemsChanged.connect([this, &settings]() {
|
|
|
|
this->threadGuard.guard();
|
|
|
|
|
|
|
|
this->onlyLogListedChannels.clear();
|
|
|
|
|
|
|
|
for (const auto &loggedChannel : *settings.loggedChannels.readOnly())
|
|
|
|
{
|
|
|
|
this->onlyLogListedChannels.insert(loggedChannel.channelName());
|
|
|
|
}
|
|
|
|
});
|
2018-01-28 14:23:55 +01:00
|
|
|
}
|
|
|
|
|
2022-07-02 11:42:28 +02:00
|
|
|
void Logging::addMessage(const QString &channelName, MessagePtr message,
|
|
|
|
const QString &platformName)
|
2018-01-28 14:23:55 +01:00
|
|
|
{
|
2023-01-15 12:47:22 +01:00
|
|
|
this->threadGuard.guard();
|
|
|
|
|
2018-10-21 13:43:02 +02:00
|
|
|
if (!getSettings()->enableLogging)
|
|
|
|
{
|
2018-01-28 14:23:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-15 12:47:22 +01:00
|
|
|
if (getSettings()->onlyLogListedChannels)
|
|
|
|
{
|
|
|
|
if (!this->onlyLogListedChannels.contains(channelName))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 11:42:28 +02:00
|
|
|
auto platIt = this->loggingChannels_.find(platformName);
|
|
|
|
if (platIt == this->loggingChannels_.end())
|
2018-10-21 13:43:02 +02:00
|
|
|
{
|
2022-07-02 11:42:28 +02:00
|
|
|
auto channel = new LoggingChannel(channelName, platformName);
|
2018-01-28 14:23:55 +01:00
|
|
|
channel->addMessage(message);
|
2022-07-02 11:42:28 +02:00
|
|
|
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));
|
2018-10-21 13:43:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-02 11:42:28 +02:00
|
|
|
chanIt->second->addMessage(message);
|
2018-01-28 14:23:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace chatterino
|