-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathlog.h
54 lines (40 loc) · 1.34 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
46
47
48
49
50
51
52
53
54
#ifndef LOG_H
#define LOG_H
#include <QMutex>
#include <QPointer>
#include <QStringList>
#include <QFile>
class DialogLogOutput;
// Logger
class Log final
{
public:
// Adds a log entry and terminates an app, writing the log buffer to log.txt
Q_NORETURN static void fatal( const QString& str );
// Adds a debug log entry
static void debug( const char * fmt, ... ) Q_ATTRIBUTE_FORMAT_PRINTF(1, 2);
// Shows the logging widget
static void showLogger();
// Initializes log with/without a file output
static void initialize( const QString& path = "" );
private:
// Only keep this number of last log lines in buffer
static const int MAX_LOG_LINES = 500;
static Log * mLog;
// Singleton getter
static Log *g();
// Add a log entry
void add( const QString& text );
// Internal stuff
Log() = default;
~Log() = default;
Log( const Log& l) = delete;
Log operator= ( const Log& l) = delete;
// All historic log entries are stored here, guarded by mMutex
QStringList mEntries;
QMutex mMutex;
QFile mOutputFile;
// Auto-set to null when log dialog is closed
QPointer<DialogLogOutput> mDialog;
};
#endif // LOG_H