/
logger.h
90 lines (64 loc) · 2.11 KB
/
logger.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef LOGGER_H
#define LOGGER_H
#ifdef _DEBUG
#include <QDebug>
#endif
#include <QObject>
#include <QList>
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include <QStringList>
#include "loggerinterface.h"
#include "loggermessage.h"
#include "logtablemodel.h"
#include "loggersettings.h"
class Logger : public QObject, public LoggerInterface
{
Q_OBJECT
public:
//maybe a singleton would be apropriate ...
explicit Logger(const QString& logFile, QObject *parent = 0);
~Logger();
void log(const QString &sender, const QString &message, MessageType type = INFO);
LogTableModel* getModel();
int getTotalMessageCount() const;
const LoggerSettings& getSettings() const;
const QStringList *getSenderList() const;
private:
//bunch of private convenient functions
void logError(const QString& msg);
void logWarning(const QString& msg);
void logInfo(const QString& msg);
void logToFile(const LoggerMessage& msg);
void logToModel(const LoggerMessage& msg);
void logToPopUp(const LoggerMessage& msg);
void prepareLogFile();
void startFileBuffering();
void stopFileBuffering();
signals:
void totalLogCountChanged(int count);
void senderListUpdated(const QString& newItem);
public slots:
void toggleFileLogging(bool enabled);
void toggleListModelLogging(bool enabled);
void togglePopUpLogging(bool enabled);
void setFileLogLevel(MessageType level);
void setListModelLogLevel(MessageType level);
void setPopUpLogLevel(MessageType level);
bool moveLog(const QString& newPath);
void flushLog();
void flushModel();
void dumpLogToFile(const QString &targetFile, MessageType level = INVALID); //INVALID means every message even non standard and forgotten updates for the enum (;
void dumpLogToString(QString &target,MessageType level = INVALID);
protected:
QList<LoggerMessage> Log;
QList<LoggerMessage> Buffer;
QStringList SenderList;
LoggerSettings Settings;
QFile* LogFile;
QTextStream* LogFileStream;
LogTableModel LogModel;
bool FileBuffering;
};
#endif // LOGGER_H