Revision f682a8cb
Von Christian Ehringfeld vor fast 9 Jahren hinzugefügt
src/logger.cpp | ||
---|---|---|
qDebug() << errorMsg;
|
||
stream << errorMsg;
|
||
}
|
||
if(logQuery) {
|
||
if(logQuery || !errorMsg.isEmpty()) {
|
||
const QString query = this->generateLogMsg(q);
|
||
if(!query.isEmpty()) {
|
||
qDebug() << query;
|
||
stream << query;
|
||
}
|
||
}
|
||
stream << "\n";
|
||
stream.flush();
|
||
log.close();
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
|
||
QString Logger::generateLogMsg(const QSqlQuery &q) const {
|
||
QString Logger::generateLogMsg(const QSqlQuery &q, bool withValues) const {
|
||
QString r = "<" + q.executedQuery() + ">";
|
||
if(withValues) {
|
||
QMap<QString, QVariant> m = q.boundValues();
|
||
QMap<QString,QVariant>::iterator i;
|
||
if(!m.isEmpty()) {
|
||
... | ... | |
r += "{" + i.key() + ":" + i.value().toString() + "}";
|
||
}
|
||
}
|
||
}
|
||
return r;
|
||
}
|
||
|
||
... | ... | |
|
||
QString Logger::generateLogMsg(const QSqlError &e) const {
|
||
if(e.isValid()) {
|
||
return "UTC:" + QDateTime::currentDateTime().toString("yyyy-MM-dd|hh:MM:ss") + "|" + e.driverText() + "|" + e.databaseText().toLatin1() + "\n";
|
||
return "ErrorUTC:" + QDateTime::currentDateTime().toString("yyyy-MM-dd|hh:MM:ss") + "|" + e.driverText() + "|" + e.databaseText().toLatin1();
|
||
} else {
|
||
return "";
|
||
}
|
Auch abrufbar als: Unified diff
example and logger update