refactor: Logging (chat logger) (#5058)

It's no longer a singleton

It's now a unique_ptr that dies together with the Application

* Add getChatLogger to EmptyApplication

* unrelated change: Access Application::instance statically

* fix logging init order

* Add changelog entry
This commit is contained in:
pajlada 2023-12-31 13:51:40 +01:00 committed by GitHub
parent 036a5f3f21
commit 65b1ed312c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 14 deletions

View file

@ -87,6 +87,7 @@
- Dev: Refactor `Emoji`'s EmojiMap into a vector. (#4980)
- Dev: Refactor `DebugCount` and add copy button to debug popup. (#4921)
- Dev: Refactor `common/Credentials`. (#4979)
- Dev: Refactor chat logger. (#5058)
- Dev: Changed lifetime of context menus. (#4924)
- Dev: Renamed `tools` directory to `scripts`. (#5035)
- Dev: Refactor `ChannelView`, removing a bunch of clang-tidy warnings. (#4926)

View file

@ -75,6 +75,12 @@ public:
return nullptr;
}
Logging *getChatLogger() override
{
assert(!"getChatLogger was called without being initialized");
return nullptr;
}
ChatterinoBadges *getChatterinoBadges() override
{
return nullptr;

View file

@ -128,12 +128,12 @@ Application::Application(Settings &_settings, Paths &_paths, const Args &_args)
, userData(&this->emplace<UserDataController>())
, sound(&this->emplace<ISoundController>(makeSoundController(_settings)))
, twitchLiveController(&this->emplace<TwitchLiveController>())
, logging(new Logging(_settings))
#ifdef CHATTERINO_HAVE_PLUGINS
, plugins(&this->emplace<PluginController>())
#endif
, logging(&this->emplace<Logging>())
{
this->instance = this;
Application::instance = this;
// We can safely ignore this signal's connection since the Application will always
// be destroyed after fonts
@ -142,6 +142,8 @@ Application::Application(Settings &_settings, Paths &_paths, const Args &_args)
});
}
Application::~Application() = default;
void Application::initialize(Settings &settings, Paths &paths)
{
assert(isAppInitialized == false);
@ -312,6 +314,11 @@ ITwitchIrcServer *Application::getTwitch()
return this->twitch;
}
Logging *Application::getChatLogger()
{
return this->logging.get();
}
void Application::save()
{
for (auto &singleton : this->singletons_)

View file

@ -68,6 +68,7 @@ public:
virtual HighlightController *getHighlights() = 0;
virtual NotificationController *getNotifications() = 0;
virtual ITwitchIrcServer *getTwitch() = 0;
virtual Logging *getChatLogger() = 0;
virtual ChatterinoBadges *getChatterinoBadges() = 0;
virtual FfzBadges *getFfzBadges() = 0;
virtual SeventvBadges *getSeventvBadges() = 0;
@ -89,6 +90,12 @@ public:
static Application *instance;
Application(Settings &_settings, Paths &_paths, const Args &_args);
~Application() override;
Application(const Application &) = delete;
Application(Application &&) = delete;
Application &operator=(const Application &) = delete;
Application &operator=(Application &&) = delete;
void initialize(Settings &settings, Paths &paths);
void load();
@ -121,14 +128,13 @@ public:
private:
TwitchLiveController *const twitchLiveController{};
const std::unique_ptr<Logging> logging;
public:
#ifdef CHATTERINO_HAVE_PLUGINS
PluginController *const plugins{};
#endif
/*[[deprecated]]*/ Logging *const logging{};
const Args &getArgs() override
{
return this->args_;
@ -175,6 +181,7 @@ public:
return this->highlights;
}
ITwitchIrcServer *getTwitch() override;
Logging *getChatLogger() override;
ChatterinoBadges *getChatterinoBadges() override
{
return this->chatterinoBadges;

View file

@ -101,7 +101,8 @@ void Channel::addMessage(MessagePtr message,
{
channelPlatform = "twitch";
}
app->logging->addMessage(this->name_, message, channelPlatform);
getIApp()->getChatLogger()->addMessage(this->name_, message,
channelPlatform);
}
if (this->messages_.pushBack(message, deleted))

View file

@ -12,7 +12,7 @@
namespace chatterino {
void Logging::initialize(Settings &settings, Paths & /*paths*/)
Logging::Logging(Settings &settings)
{
// We can safely ignore this signal connection since settings are only-ever destroyed
// on application exit

View file

@ -1,6 +1,5 @@
#pragma once
#include "common/Singleton.hpp"
#include "util/QStringHash.hpp"
#include "util/ThreadGuard.hpp"
@ -12,19 +11,15 @@
namespace chatterino {
class Paths;
class Settings;
struct Message;
using MessagePtr = std::shared_ptr<const Message>;
class LoggingChannel;
class Logging : public Singleton
class Logging
{
Paths *pathManager = nullptr;
public:
Logging() = default;
void initialize(Settings &settings, Paths &paths) override;
Logging(Settings &settings);
void addMessage(const QString &channelName, MessagePtr message,
const QString &platformName);