-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmylogger.cpp
More file actions
54 lines (47 loc) · 1.42 KB
/
mylogger.cpp
File metadata and controls
54 lines (47 loc) · 1.42 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
49
50
51
52
53
54
#include "mylogger.h"
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QDebug>
#include <QDir>
#ifdef Q_OS_WIN
#include <QtMessageHandler>
QFile file("c:/tmp/psyncguilog.txt");
//QFile file(QDir::tempPath()+ "/psyncguilog.txt");
QTextStream out(&file);
static void SimpleLoggingHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
switch (type) {
case QtDebugMsg:
file.open(QIODevice::Append | QIODevice::Text);
out<<"Debug msg "<<QDateTime::currentDateTime().toString()<< " " <<msg<<"\n";
out.flush();
file.close();
break;
case QtCriticalMsg:
file.open(QIODevice::Append | QIODevice::Text);
out<<"Critical msg "<<QDateTime::currentDateTime().toString() << " "<<msg<<"\n";
out.flush();
file.close();
break;
case QtWarningMsg:
file.open(QIODevice::Append | QIODevice::Text);
out<<"Warning msg "<<QDateTime::currentDateTime().toString()<< " "<<msg<<"\n";
out.flush();
file.close();
break;
case QtFatalMsg:
file.open(QIODevice::Append | QIODevice::Text);
out<<"Fatal msg "<<QDateTime::currentDateTime().toString() <<" "<<msg<<"\n";
out.flush();
file.close();
abort();
}
}
MyLogger::MyLogger(QObject *parent) :
QObject(parent)
{
qInstallMessageHandler(SimpleLoggingHandler);
qDebug()<<"from file";
}
#endif