-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.h
45 lines (42 loc) · 1.04 KB
/
log.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include <QString>
#include <QFile>
#include <queue>
#include "globals.h"
#include "settings.h"
class Entry
{
public:
Entry(const QString &message,const QString &operation,const QString &subsystem="logger")
{
data=QString("== %1").arg(subsystem.toUpper());
if (!operation.isEmpty()) data.append(QString(" (%1)").arg(operation.toUpper()));
data.append(QString("\n%1").arg(message));
if (data.back() != '\n') data.append("\n");
}
operator QString() const { return data; }
operator QByteArray() const { return StringConvert::ByteArray(data); }
protected:
QString data;
};
class Log : public QObject
{
Q_OBJECT
public:
Log(QObject *parent=nullptr);
~Log();
ApplicationSetting& Directory();
protected:
ApplicationSetting settingLogDirectory;
QFile file;
std::queue<Entry> hold;
bool CreateDirectory();
void Write(const Entry &entry);
signals:
void Print(const Entry &entry);
public slots:
bool Open();
void Close();
void Receive(const QString &message,const QString &operation,const QString &subsystem);
void Archive();
};