-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (59 loc) · 1.78 KB
/
main.cpp
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
#include <QCoreApplication>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QString>
#include <QFileInfoList>
#include <QDir>
#include "lib/nfcthread.h"
void myMessageHandler(QtMsgType type, const QMessageLogContext &context,const QString &msg)
{
QString txt = QDateTime::currentDateTime().toString("dd-MM-yy hh:mm:ss")+" ";
switch (type) {
case QtDebugMsg:
txt += "Debug: " + msg;
break;
case QtWarningMsg:
txt += "Warning: " + msg;
break;
case QtCriticalMsg:
txt += "Critical: " + msg;
break;
case QtFatalMsg:
txt += "Fatal: " + msg;
abort();
}
QFile outFile;
QString pathLog = "/var/log/";
if(QString(getenv("USER"))=="alberto"){
pathLog = "";
}
outFile.setFileName(pathLog+"alubadge.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
if(outFile.size()>15728640){
QDir dir(pathLog);
QStringList filter;
filter << "alucount.*.log";
dir.setNameFilters(filter);
QFileInfoList listFs = dir.entryInfoList(QDir::Files,QDir::Time);
if(listFs.size()>5){
for(int i = 5; i < listFs.size();i++){
QFile::remove(listFs.at(i).absoluteFilePath());
}
}
outFile.rename(pathLog+"alucount.log",pathLog+"alucount."+QDateTime::currentDateTime().toString("dd-MM-yy_hh:mm")+".log");
outFile.close();
outFile.setFileName(pathLog+"alucount.log");
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
}
QTextStream ts(&outFile);
ts << txt << endl;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
qInstallMessageHandler(myMessageHandler);
NfcThread nfcTh;
nfcTh.start();
return a.exec();
}