refactor: Logger is now a proper singleton

This commit is contained in:
sithlord48
2025-11-13 10:36:45 -05:00
committed by Chris Rizzitello
parent 8256a3ba43
commit ec9f7efcff
2 changed files with 8 additions and 7 deletions

View File

@ -25,6 +25,10 @@ public:
Q_SIGNALS:
void newLine(const QString &line);
private:
explicit Logger() = default;
~Logger() = default;
};
} // namespace deskflow::gui

View File

@ -30,13 +30,11 @@ void LoggerTests::initTestCase()
void LoggerTests::newLine()
{
Logger logger;
QSignalSpy spy(&logger, &Logger::newLine);
QSignalSpy spy(Logger::instance(), &Logger::newLine);
QVERIFY(spy.isValid());
Settings::setValue(Settings::Log::GuiDebug, true);
logger.handleMessage(QtDebugMsg, "stub", "test");
Logger::instance()->handleMessage(QtDebugMsg, "stub", "test");
QCOMPARE(spy.count(), 1);
QVERIFY(qvariant_cast<QString>(spy.takeFirst().at(0)).contains("test"));
@ -45,14 +43,13 @@ void LoggerTests::newLine()
void LoggerTests::noNewLine()
{
Logger logger;
bool newLineEmitted = false;
QSignalSpy spy(&logger, &Logger::newLine);
QSignalSpy spy(Logger::instance(), &Logger::newLine);
QVERIFY(spy.isValid());
Settings::setValue(Settings::Log::GuiDebug, false);
logger.handleMessage(QtDebugMsg, "stub", "test");
Logger::instance()->handleMessage(QtDebugMsg, "stub", "test");
QCOMPARE(spy.count(), 0);
QVERIFY(!newLineEmitted);
}