9 using namespace stefanfrings;
11 LogMessage::LogMessage(
const QtMsgType type,
const QString& message,
const QHash<QString, QString> *logVars,
const QString &file,
const QString &
function,
const int line)
14 this->message=message;
16 this->
function=
function;
18 timestamp=QDateTime::currentDateTime();
19 threadId=QThread::currentThreadId();
25 this->logVars=*logVars;
31 QString decorated=msgFormat+
"\n";
32 decorated.replace(
"{msg}",message);
34 if (decorated.contains(
"{timestamp}"))
36 decorated.replace(
"{timestamp}",timestamp.toString(timestampFormat));
41 decorated.replace(
"{typeNr}",typeNr);
46 decorated.replace(
"{type}",
"DEBUG ");
49 decorated.replace(
"{type}",
"WARNING ");
52 decorated.replace(
"{type}",
"CRITICAL");
55 decorated.replace(
"{type}",
"FATAL ");
57 #if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
59 decorated.replace(
"{type}",
"INFO ");
64 decorated.replace(
"{file}",file);
65 decorated.replace(
"{function}",
function);
66 decorated.replace(
"{line}",QString::number(line));
68 QString threadId = QString(
"0x%1").arg(qulonglong(QThread::currentThreadId()), 8, 16, QLatin1Char(
'0'));
69 decorated.replace(
"{thread}",threadId);
72 if (decorated.contains(
"{") && !logVars.isEmpty())
74 QList<QString> keys=logVars.keys();
75 foreach (QString key, keys)
77 decorated.replace(
"{"+key+
"}",logVars.value(key));
QString toString(const QString &msgFormat, const QString ×tampFormat) const
Returns the log message as decorated string.
QtMsgType getType() const
Get the message type.
LogMessage(const QtMsgType type, const QString &message, const QHash< QString, QString > *logVars, const QString &file, const QString &function, const int line)
Constructor.