Structure messages before write them
The current code use a string to concatenate the full message before delegating to destination the write process
void dtkLogEnginePrivate::writeLevel(void) const
{
...
QString message = QString("[%1] - %2 - %3")
.arg(dtk::logLevelToString(this->level))
.arg(QDateTime::currentDateTime().toString())
.arg(this->buffer);
...
dtkLogger::instance().write(message);
...
}
The problem is that when one wants to display the message, it has to reverse engineering the string to get the pieces of information.
An alternate solution would be to use a QHash<QString, QString>
to store the message before delegate the write process to the destination.
void dtkLogEnginePrivate::writeLevel(void) const
{
...
QHash<QString, QString> message;
message[QStringLiterral("level")] = dtk::logLevelToString(this->level);
message[QStringLiterral("date")] = QDateTime::currentDateTime().toString();
message[QStringLiterral("buffer")] = this->buffer;
...
dtkLogger::instance().write(message);
...
}
Edited by KLOCZKO Thibaud