-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
37 lines (34 loc) · 676 Bytes
/
log.cpp
File metadata and controls
37 lines (34 loc) · 676 Bytes
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
#include "lib.h"
void LOGF(QString str, int level)
{
static bool _INIT_ = false;
static QFile fd("game.log");
static QTextStream outs;
QString timeVal = QDateTime::currentDateTime().toString("mm:ss") + "\t";
if (logArea)
logArea->append(timeVal + str);
if (!_INIT_) {
if (!fd.open(QIODevice::WriteOnly | QIODevice::Text))
return;
outs.setDevice(&fd);
_INIT_ = true;
}
switch (level) {
case 0:
outs << timeVal << str << "\n";
break;
case 1:
outs << str << "\n";
break;
case -1:
LOGF(str);
outs << "_EOF_\n\n";
_INIT_ = false;
fd.close();
break;
default:
outs << "WARNING: Invalid log level\t" << str;
outs.flush();
break;
}
}