-
Notifications
You must be signed in to change notification settings - Fork 1
/
Logger.cpp
executable file
·67 lines (51 loc) · 1.37 KB
/
Logger.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
#include <httq/Logger.h>
#include <QCoreApplication>
#include <QDebug>
namespace httq
{
// LoggerFactory
Logger *LoggerFactory::createLogger(QObject *parent)
{
return new Logger(this, parent);
}
// Logger
Logger::Logger(LoggerFactory *loggerFactory, QObject *parent)
: QObject(parent)
, mLoggerFactory(loggerFactory)
{
if (parent == nullptr)
mPath = QStringLiteral("Global");
else
{
mPath = QString::fromUtf8(parent->metaObject()->className());
// do
// {
// mPath.prepend(QString::fromUtf8(parent->metaObject()->className()));
// mPath.prepend(QStringLiteral(" => "));
// }
// while ((parent = parent->parent()));
// mPath.remove(0, QString(QStringLiteral(" => ")).length()); // hacky - remove first separator
// if (mPath.length() > 30)
// mPath = QStringLiteral("...%1").arg(mPath.right(30));
//qWarning() << "new Logger" << mPath;
}
}
void Logger::debug(const QString &message)
{
//qtLogger(QStringLiteral("DEBUG"), qWarning()) << message; //qDebug()) << message;
}
void Logger::warning(const QString &message)
{
qtLogger(QStringLiteral("WARNING"), qWarning()) << message;
}
void Logger::error(const QString &message)
{
qtLogger(QStringLiteral("ERROR"), qCritical()) << message;
}
QDebug Logger::qtLogger(const QString &type, QDebug logger)
{
QDebug d(logger.noquote());
d << type << mPath << ":";
return d;
}
}