-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (41 loc) · 1.53 KB
/
Copy pathmain.cpp
File metadata and controls
48 lines (41 loc) · 1.53 KB
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
#include "kaffeine.h"
#include <QApplication>
#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include <QDir>
#include <QDateTime>
void KaffeineMsgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString txt;
QByteArray localMsg = msg.toLocal8Bit();
QByteArray timeMsg = QDateTime::currentDateTime().toString().toLocal8Bit();
switch (type) {
case QtDebugMsg:
txt.sprintf("[%s] Debug: %s (%s:%u, %s)\n", timeMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
txt.sprintf("[%s] Warning: %s (%s:%u, %s)\n", timeMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
txt.sprintf("[%s] Critical: %s (%s:%u, %s)\n", timeMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
txt.sprintf("[%s] Fatal: %s (%s:%u, %s)\n", timeMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
break;
}
QDir dir(QDir::homePath() + "/.local/share/");
dir.mkpath("Kaffeine");
QFile outFile(QDir::homePath() + "/.local/share/Kaffeine/log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(KaffeineMsgHandler);
Kaffeine k;
k.show();
return a.exec();
}