Add feature to select channels to log (#4302)

* Add checkbox for custom logging and table with channels to log on Logs page

* Add checkbox to enable and disable logging per channel

* Return from addMessage before logging if custom logging enabled and channel does not have logging enabled

* Use clang-format to fix formatting

* Add CHANGELOG.md entry

* Resolve PR comments

* Remove toggle for channels so any channel listed will be logged

* Move Only log channels listed below checkbox to just above table

* Fix formatting

* Re-order changelog

* ChannelLog constructor: Copy & move instead of const ref & copy

* ChannelLog::createEmpty: Curly brace initialize instead of repeating
name

* ChannelLog toString & createEmpty: nodiscard

* Use COUNT paradigm in model column

* Remove ChanneLoggingModel source file comments

* Use Column::Channel in getRowFromItem

* Rename `getItemFromRow` parameter and mark it as unused

* Curly brace initialize ChannelLog

* private & friend class the model

* Filter out channels to log using a set instead of iterating over a vector every time a message comes in

* Rename `ChannelLog::channel` member to `ChannelLog::channelName`

Also made it private

* mini comment on ChannelLog

Co-authored-by: Felanbird <41973452+Felanbird@users.noreply.github.com>
Co-authored-by: Rasmus Karlsson <rasmus.karlsson@pajlada.com>
This commit is contained in:
askepticaldreamer
2023-01-15 03:47:22 -08:00
committed by GitHub
parent a567cc5ae7
commit 4c782ce90c
11 changed files with 225 additions and 6 deletions
+21 -3
View File
@@ -1,6 +1,5 @@
#include "singletons/Logging.hpp"
#include "Application.hpp"
#include "singletons/helper/LoggingChannel.hpp"
#include "singletons/Paths.hpp"
#include "singletons/Settings.hpp"
@@ -9,23 +8,42 @@
#include <QStandardPaths>
#include <memory>
#include <unordered_map>
#include <utility>
namespace chatterino {
void Logging::initialize(Settings &settings, Paths &paths)
void Logging::initialize(Settings &settings, Paths & /*paths*/)
{
settings.loggedChannels.delayedItemsChanged.connect([this, &settings]() {
this->threadGuard.guard();
this->onlyLogListedChannels.clear();
for (const auto &loggedChannel : *settings.loggedChannels.readOnly())
{
this->onlyLogListedChannels.insert(loggedChannel.channelName());
}
});
}
void Logging::addMessage(const QString &channelName, MessagePtr message,
const QString &platformName)
{
this->threadGuard.guard();
if (!getSettings()->enableLogging)
{
return;
}
if (getSettings()->onlyLogListedChannels)
{
if (!this->onlyLogListedChannels.contains(channelName))
{
return;
}
}
auto platIt = this->loggingChannels_.find(platformName);
if (platIt == this->loggingChannels_.end())
{
+7
View File
@@ -1,11 +1,14 @@
#pragma once
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include "util/ThreadGuard.hpp"
#include <QString>
#include <map>
#include <memory>
#include <unordered_set>
namespace chatterino {
@@ -32,6 +35,10 @@ private:
std::map<PlatformName,
std::map<ChannelName, std::unique_ptr<LoggingChannel>>>
loggingChannels_;
// Keeps the value of the `loggedChannels` settings
std::unordered_set<ChannelName> onlyLogListedChannels;
ThreadGuard threadGuard;
};
} // namespace chatterino
+2
View File
@@ -25,6 +25,7 @@ ConcurrentSettings::ConcurrentSettings()
, filterRecords(*new SignalVector<FilterRecordPtr>())
, nicknames(*new SignalVector<Nickname>())
, moderationActions(*new SignalVector<ModerationAction>)
, loggedChannels(*new SignalVector<ChannelLog>)
{
persist(this->highlightedMessages, "/highlighting/highlights");
persist(this->blacklistedUsers, "/highlighting/blacklist");
@@ -36,6 +37,7 @@ ConcurrentSettings::ConcurrentSettings()
persist(this->nicknames, "/nicknames");
// tagged users?
persist(this->moderationActions, "/moderation/actions");
persist(this->loggedChannels, "/logging/channels");
}
bool ConcurrentSettings::isHighlightedUser(const QString &username)
+4
View File
@@ -3,6 +3,7 @@
#include "BaseSettings.hpp"
#include "common/Channel.hpp"
#include "common/SignalVector.hpp"
#include "controllers/logging/ChannelLog.hpp"
#include "singletons/Toasts.hpp"
#include "util/RapidJsonSerializeQString.hpp"
#include "util/StreamerMode.hpp"
@@ -40,6 +41,7 @@ public:
SignalVector<FilterRecordPtr> &filterRecords;
SignalVector<Nickname> &nicknames;
SignalVector<ModerationAction> &moderationActions;
SignalVector<ChannelLog> &loggedChannels;
bool isHighlightedUser(const QString &username);
bool isBlacklistedUser(const QString &username);
@@ -364,6 +366,8 @@ public:
/// Logging
BoolSetting enableLogging = {"/logging/enabled", false};
BoolSetting onlyLogListedChannels = {"/logging/onlyLogListedChannels",
false};
QStringSetting logPath = {"/logging/path", ""};