-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageHandler.cpp
More file actions
30 lines (25 loc) · 1.01 KB
/
messageHandler.cpp
File metadata and controls
30 lines (25 loc) · 1.01 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
//messageHandler.cpp
#include "messageHandler.h"
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QStandardPaths>
#include <QDir>
void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg)
{
static bool firstRun = true;
QString path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) + "/AccessibleAtlas";
QDir().mkpath(path);
QFile outFile(path + "/AccessibleAtlas.log");
// On the very first call, use Truncate to wipe the file
// Otherwise use Append so do not overwrite logs from 2 seconds ago
auto openMode = firstRun ? (QIODevice::WriteOnly | QIODevice::Truncate)
: (QIODevice::WriteOnly | QIODevice::Append);
if (outFile.open(openMode))
{
firstRun = false; // Set to false so we append for the rest of the session
QTextStream stream(&outFile);
//QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
stream << msg << Qt::endl;
}
}