mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
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:
parent
036a5f3f21
commit
65b1ed312c
|
@ -87,6 +87,7 @@
|
||||||
- Dev: Refactor `Emoji`'s EmojiMap into a vector. (#4980)
|
- Dev: Refactor `Emoji`'s EmojiMap into a vector. (#4980)
|
||||||
- Dev: Refactor `DebugCount` and add copy button to debug popup. (#4921)
|
- Dev: Refactor `DebugCount` and add copy button to debug popup. (#4921)
|
||||||
- Dev: Refactor `common/Credentials`. (#4979)
|
- Dev: Refactor `common/Credentials`. (#4979)
|
||||||
|
- Dev: Refactor chat logger. (#5058)
|
||||||
- Dev: Changed lifetime of context menus. (#4924)
|
- Dev: Changed lifetime of context menus. (#4924)
|
||||||
- Dev: Renamed `tools` directory to `scripts`. (#5035)
|
- Dev: Renamed `tools` directory to `scripts`. (#5035)
|
||||||
- Dev: Refactor `ChannelView`, removing a bunch of clang-tidy warnings. (#4926)
|
- Dev: Refactor `ChannelView`, removing a bunch of clang-tidy warnings. (#4926)
|
||||||
|
|
|
@ -75,6 +75,12 @@ public:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logging *getChatLogger() override
|
||||||
|
{
|
||||||
|
assert(!"getChatLogger was called without being initialized");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
ChatterinoBadges *getChatterinoBadges() override
|
ChatterinoBadges *getChatterinoBadges() override
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -128,12 +128,12 @@ Application::Application(Settings &_settings, Paths &_paths, const Args &_args)
|
||||||
, userData(&this->emplace<UserDataController>())
|
, userData(&this->emplace<UserDataController>())
|
||||||
, sound(&this->emplace<ISoundController>(makeSoundController(_settings)))
|
, sound(&this->emplace<ISoundController>(makeSoundController(_settings)))
|
||||||
, twitchLiveController(&this->emplace<TwitchLiveController>())
|
, twitchLiveController(&this->emplace<TwitchLiveController>())
|
||||||
|
, logging(new Logging(_settings))
|
||||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||||
, plugins(&this->emplace<PluginController>())
|
, plugins(&this->emplace<PluginController>())
|
||||||
#endif
|
#endif
|
||||||
, logging(&this->emplace<Logging>())
|
|
||||||
{
|
{
|
||||||
this->instance = this;
|
Application::instance = this;
|
||||||
|
|
||||||
// We can safely ignore this signal's connection since the Application will always
|
// We can safely ignore this signal's connection since the Application will always
|
||||||
// be destroyed after fonts
|
// 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)
|
void Application::initialize(Settings &settings, Paths &paths)
|
||||||
{
|
{
|
||||||
assert(isAppInitialized == false);
|
assert(isAppInitialized == false);
|
||||||
|
@ -312,6 +314,11 @@ ITwitchIrcServer *Application::getTwitch()
|
||||||
return this->twitch;
|
return this->twitch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logging *Application::getChatLogger()
|
||||||
|
{
|
||||||
|
return this->logging.get();
|
||||||
|
}
|
||||||
|
|
||||||
void Application::save()
|
void Application::save()
|
||||||
{
|
{
|
||||||
for (auto &singleton : this->singletons_)
|
for (auto &singleton : this->singletons_)
|
||||||
|
|
|
@ -68,6 +68,7 @@ public:
|
||||||
virtual HighlightController *getHighlights() = 0;
|
virtual HighlightController *getHighlights() = 0;
|
||||||
virtual NotificationController *getNotifications() = 0;
|
virtual NotificationController *getNotifications() = 0;
|
||||||
virtual ITwitchIrcServer *getTwitch() = 0;
|
virtual ITwitchIrcServer *getTwitch() = 0;
|
||||||
|
virtual Logging *getChatLogger() = 0;
|
||||||
virtual ChatterinoBadges *getChatterinoBadges() = 0;
|
virtual ChatterinoBadges *getChatterinoBadges() = 0;
|
||||||
virtual FfzBadges *getFfzBadges() = 0;
|
virtual FfzBadges *getFfzBadges() = 0;
|
||||||
virtual SeventvBadges *getSeventvBadges() = 0;
|
virtual SeventvBadges *getSeventvBadges() = 0;
|
||||||
|
@ -89,6 +90,12 @@ public:
|
||||||
static Application *instance;
|
static Application *instance;
|
||||||
|
|
||||||
Application(Settings &_settings, Paths &_paths, const Args &_args);
|
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 initialize(Settings &settings, Paths &paths);
|
||||||
void load();
|
void load();
|
||||||
|
@ -121,14 +128,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TwitchLiveController *const twitchLiveController{};
|
TwitchLiveController *const twitchLiveController{};
|
||||||
|
const std::unique_ptr<Logging> logging;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||||
PluginController *const plugins{};
|
PluginController *const plugins{};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*[[deprecated]]*/ Logging *const logging{};
|
|
||||||
|
|
||||||
const Args &getArgs() override
|
const Args &getArgs() override
|
||||||
{
|
{
|
||||||
return this->args_;
|
return this->args_;
|
||||||
|
@ -175,6 +181,7 @@ public:
|
||||||
return this->highlights;
|
return this->highlights;
|
||||||
}
|
}
|
||||||
ITwitchIrcServer *getTwitch() override;
|
ITwitchIrcServer *getTwitch() override;
|
||||||
|
Logging *getChatLogger() override;
|
||||||
ChatterinoBadges *getChatterinoBadges() override
|
ChatterinoBadges *getChatterinoBadges() override
|
||||||
{
|
{
|
||||||
return this->chatterinoBadges;
|
return this->chatterinoBadges;
|
||||||
|
|
|
@ -101,7 +101,8 @@ void Channel::addMessage(MessagePtr message,
|
||||||
{
|
{
|
||||||
channelPlatform = "twitch";
|
channelPlatform = "twitch";
|
||||||
}
|
}
|
||||||
app->logging->addMessage(this->name_, message, channelPlatform);
|
getIApp()->getChatLogger()->addMessage(this->name_, message,
|
||||||
|
channelPlatform);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->messages_.pushBack(message, deleted))
|
if (this->messages_.pushBack(message, deleted))
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace chatterino {
|
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
|
// We can safely ignore this signal connection since settings are only-ever destroyed
|
||||||
// on application exit
|
// on application exit
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/Singleton.hpp"
|
|
||||||
#include "util/QStringHash.hpp"
|
#include "util/QStringHash.hpp"
|
||||||
#include "util/ThreadGuard.hpp"
|
#include "util/ThreadGuard.hpp"
|
||||||
|
|
||||||
|
@ -12,19 +11,15 @@
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
class Paths;
|
class Settings;
|
||||||
struct Message;
|
struct Message;
|
||||||
using MessagePtr = std::shared_ptr<const Message>;
|
using MessagePtr = std::shared_ptr<const Message>;
|
||||||
class LoggingChannel;
|
class LoggingChannel;
|
||||||
|
|
||||||
class Logging : public Singleton
|
class Logging
|
||||||
{
|
{
|
||||||
Paths *pathManager = nullptr;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Logging() = default;
|
Logging(Settings &settings);
|
||||||
|
|
||||||
void initialize(Settings &settings, Paths &paths) override;
|
|
||||||
|
|
||||||
void addMessage(const QString &channelName, MessagePtr message,
|
void addMessage(const QString &channelName, MessagePtr message,
|
||||||
const QString &platformName);
|
const QString &platformName);
|
||||||
|
|
Loading…
Reference in a new issue