Cockatrice/cockatrice/src/interface/logger.h
BruebachL f24c36d6b1
Core qt module for libs (#6278)
* Move logger and key signals from libcockatrice_utility to Cockatrice.

Took 9 minutes

* Only link Qt::Core instead of COCKATRICE_QT_MODULES to libraries, if possible.

Took 2 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2025-11-05 18:51:08 +01:00

72 lines
1.5 KiB
C++

/**
* @file logger.h
* @ingroup Core
* @brief TODO: Document this.
*/
#ifndef LOGGER_H
#define LOGGER_H
#include <QFile>
#include <QMutex>
#include <QString>
#include <QTextStream>
#include <QVector>
#if defined(Q_PROCESSOR_X86_32)
#define BUILD_ARCHITECTURE "32-bit"
#elif defined(Q_PROCESSOR_X86_64)
#define BUILD_ARCHITECTURE "64-bit"
#elif defined(Q_PROCESSOR_ARM)
#define BUILD_ARCHITECTURE "ARM"
#else
#define BUILD_ARCHITECTURE "unknown"
#endif
class Logger : public QObject
{
Q_OBJECT
public:
static Logger &getInstance()
{
static Logger instance;
return instance;
}
void logToFile(bool enabled);
void log(QtMsgType type, const QMessageLogContext &ctx, const QString &message);
QString getClientVersion();
QString getClientOperatingSystem();
QString getSystemArchitecture();
QString getSystemLocale();
QString getClientInstallInfo();
QList<QString> getLogBuffer()
{
return logBuffer;
}
private:
Logger();
~Logger() override;
// Singleton - Don't implement copy constructor and assign operator
Logger(Logger const &);
void operator=(Logger const &);
bool logToFileEnabled;
QTextStream fileStream;
QFile fileHandle;
QList<QString> logBuffer;
QMutex mutex;
protected:
void openLogfileSession();
void closeLogfileSession();
protected slots:
void internalLog(const QString &message);
signals:
void logEntryAdded(const QString &message);
};
#endif