45 lines
898 B
C++
45 lines
898 B
C++
#pragma once
|
|
|
|
#include <QDateTime>
|
|
#include <QList>
|
|
#include <QMutex>
|
|
#include <QObject>
|
|
#include <QString>
|
|
|
|
namespace Cevo {
|
|
|
|
struct DebugLogItem {
|
|
QDateTime time;
|
|
QString group;
|
|
QString text;
|
|
};
|
|
|
|
// Equivalent of DebugLog.pas's TDebugLog: a thread-safe, capped, optionally
|
|
// file-backed log.
|
|
class DebugLog : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit DebugLog(QObject *parent = nullptr);
|
|
|
|
void add(QString text, QString group = QString());
|
|
void writeToFile(QString text) const;
|
|
|
|
QList<DebugLogItem> items() const;
|
|
|
|
int maxCount() const { return m_maxCount; }
|
|
void setMaxCount(int value);
|
|
|
|
QString fileName = QStringLiteral("DebugLog.txt");
|
|
bool writeToFileEnable = false;
|
|
|
|
signals:
|
|
void newItem(const DebugLogItem &item);
|
|
|
|
private:
|
|
mutable QMutex m_lock;
|
|
QList<DebugLogItem> m_items;
|
|
int m_maxCount = 100;
|
|
};
|
|
|
|
} // namespace Cevo
|