42 lines
814 B
C++
42 lines
814 B
C++
#ifndef LOGGER_H
|
|
#define LOGGER_H
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#include <QMutex>
|
|
|
|
class Logger : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
static Logger* instance();
|
|
|
|
void setLogFile(const QString &filePath);
|
|
void setMaxLines(int maxLines);
|
|
|
|
void log(const QString &message);
|
|
void debug(const QString &message);
|
|
void info(const QString &message);
|
|
void warning(const QString &message);
|
|
void error(const QString &message);
|
|
|
|
private:
|
|
explicit Logger(QObject *parent = nullptr);
|
|
~Logger();
|
|
|
|
void writeLog(const QString &level, const QString &message);
|
|
void checkAndTrimLog();
|
|
|
|
static Logger *s_instance;
|
|
|
|
QString m_logFilePath;
|
|
int m_maxLines;
|
|
QMutex m_mutex;
|
|
int m_currentLines;
|
|
};
|
|
|
|
#endif // LOGGER_H
|