-
Notifications
You must be signed in to change notification settings - Fork 0
/
LogHandler.h
67 lines (52 loc) · 1.39 KB
/
LogHandler.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef LOGHANDLER_H
#define LOGHANDLER_H
#include <QFile>
#include <QDate>
#include <QMutex>
#include <QMutexLocker>
#include <QDir>
#include <QRegularExpression>
#include <Windows.h>
#include <DbgHelp.h>
enum LogLevel {
DebugLevel,
InfoLevel,
WarningLevel,
CriticalLevel,
FatalLevel,
Undefined,
};
class LogHandler
{
public:
static LogHandler& instance();
static void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);
static LONG UnhandledExceptionFilter(EXCEPTION_POINTERS *exceptionInfo);
void writeLog(QtMsgType type, const QString& tag, const QString& msg);
void rotateLogs();
void setLogLevel(LogLevel level);
LogLevel logLevel() const;
void clearBuffer();
private:
LogHandler();
~LogHandler();
struct LogEntry {
QtMsgType type;
QString tag;
QString msg;
};
typedef QVector<LogEntry> LogBuffer;
bool enablePrint(QtMsgType type);
void backupOldLogs();
void deleteOldLogs();
QString extractFunctionName(const QString &functionSignature);
void bufferLog(QtMsgType type, const QString &tag, const QString &msg);
QDir mLogDir;
QFile mLogFile;
QMutex mMutex;
QDate mLogDate;
LogLevel mLogLevel;
LogBuffer mLogBuffer;
};
// LONG WINAPI CustomUnhandledExceptionFilter(EXCEPTION_POINTERS *exceptionInfo);
#endif // LOGHANDLER_H