-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebugmessages.cpp
More file actions
69 lines (62 loc) · 2.34 KB
/
debugmessages.cpp
File metadata and controls
69 lines (62 loc) · 2.34 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2023 by Linwood Ferguson, licensed under GNU GPLv3
#include "debugmessages.h"
#include <QTime>
#include <QMutex>
#include <QRegularExpression>
#include <stdio.h>
#include <stdlib.h>
#include <exception>
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
// Note this just won't be accurate in terms of time across midnight but who cares it's just debug output.
static bool initdone;
static int msStartTime;
static int msLastTime;
int msElapsed;
int msThisTime;
QTime t;
static QMutex mutex;
const static QRegularExpression re = QRegularExpression("\\(.+\\).*");
mutex.lock();
if(!initdone)
{
t = QTime::currentTime();
msElapsed=0;
msThisTime=0;
msLastTime = t.msecsSinceStartOfDay();
msStartTime = msLastTime;
fprintf(stderr, "Elapsed - this : Message (Times are in milliseconds, elapsed time not CPU\n");
initdone=1;
}
else
{
t = QTime::currentTime();
msThisTime = t.msecsSinceStartOfDay() - msLastTime;
msElapsed = t.msecsSinceStartOfDay() - msStartTime;
msLastTime = t.msecsSinceStartOfDay();
}
mutex.unlock();
QByteArray localMsg = msg.toLocal8Bit();
QString qfunc = context.function;
qfunc.remove(re);
std::string sfunc(qfunc.toStdString());
const char* func = sfunc.c_str();
switch (type)
{
case QtDebugMsg:
fprintf(stderr, "%'9d - %'6d : Debug: %s (%s)\n", msElapsed, msThisTime, func, localMsg.constData());
break;
case QtInfoMsg:
fprintf(stderr, "%'9d - %'6d : Info: %s:%u, %s (%s)\n", msElapsed, msThisTime, context.file, context.line, func, localMsg.constData());
break;
case QtWarningMsg:
fprintf(stderr, "%'9d - %'6d : Warning: %s:%u, %s (%s)\n", msElapsed, msThisTime, context.file, context.line, func, localMsg.constData());
break;
case QtCriticalMsg:
fprintf(stderr, "%'9d - %'6d : Critical: %s:%u, %s (%s)\n", msElapsed, msThisTime, context.file, context.line, func, localMsg.constData());
break;
case QtFatalMsg:
fprintf(stderr, "%'9d - %'6d : Fatal: %s:%u, %s (%s)\n", msElapsed, msThisTime, context.file, context.line, func, localMsg.constData());
abort();
}
}