diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-05-21 16:23:48 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-05-26 17:41:10 +0300 |
commit | 81c78fd0db506c5a38b6ae84976d36ec5bffbb0d (patch) | |
tree | ed4dbdaad9191fa4583bbe0e489057b7a5072c03 /src | |
parent | 2b1655170f3b831d1c2f16450feb99390cfca2ba (diff) |
Improve job logging
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/connectionvalidator.cpp | 20 | ||||
-rw-r--r-- | src/gui/connectionvalidator.h | 1 | ||||
-rw-r--r-- | src/libsync/abstractnetworkjob.cpp | 14 | ||||
-rw-r--r-- | src/libsync/abstractnetworkjob.h | 7 |
4 files changed, 23 insertions, 19 deletions
diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 508e09229..d44117cad 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -91,7 +91,11 @@ void ConnectionValidator::slotCheckServerAndAuth() checkJob->setTimeout(timeoutToUseMsec); connect(checkJob, &CheckServerJob::instanceFound, this, &ConnectionValidator::slotStatusFound); connect(checkJob, &CheckServerJob::instanceNotFound, this, &ConnectionValidator::slotNoStatusFound); - connect(checkJob, &CheckServerJob::timeout, this, &ConnectionValidator::slotJobTimeout); + connect(checkJob, &CheckServerJob::timeout, this, [checkJob, this] { + qCWarning(lcConnectionValidator) << checkJob; + _errors.append(tr("timeout")); + reportResult(Timeout); + }); checkJob->start(); } @@ -135,7 +139,7 @@ void ConnectionValidator::slotStatusFound(const QUrl &url, const QJsonObject &in void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) { auto job = qobject_cast<CheckServerJob *>(sender()); - qCWarning(lcConnectionValidator) << reply->error() << job->errorString() << reply->peek(1024); + qCWarning(lcConnectionValidator) << reply->error() << job << reply->peek(1024); if (reply->error() == QNetworkReply::SslHandshakeFailedError) { reportResult(SslError); return; @@ -152,15 +156,6 @@ void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) reportResult(StatusNotFound); } -void ConnectionValidator::slotJobTimeout(const QUrl &url) -{ - Q_UNUSED(url); - //_errors.append(tr("Unable to connect to %1").arg(url.toString())); - _errors.append(tr("timeout")); - reportResult(Timeout); -} - - void ConnectionValidator::checkAuthentication() { AbstractCredentials *creds = _account->credentials(); @@ -193,7 +188,7 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) } else if (reply->error() == QNetworkReply::AuthenticationRequiredError || !_account->credentials()->stillValid(reply)) { - qCWarning(lcConnectionValidator) << "******** Password is wrong!" << reply->error() << job->errorString(); + qCWarning(lcConnectionValidator) << "******** Password is wrong!" << reply->error() << job; _errors << tr("The provided credentials are not correct"); stat = CredentialsWrong; @@ -256,7 +251,6 @@ void ConnectionValidator::fetchUser() bool ConnectionValidator::setAndCheckServerVersion(const QString &version) { - qCInfo(lcConnectionValidator) << _account->url() << "has server version" << version; _account->setServerVersion(version); // We cannot deal with servers < 7.0.0 diff --git a/src/gui/connectionvalidator.h b/src/gui/connectionvalidator.h index f21893409..27eb09a43 100644 --- a/src/gui/connectionvalidator.h +++ b/src/gui/connectionvalidator.h @@ -115,7 +115,6 @@ protected slots: void slotStatusFound(const QUrl &url, const QJsonObject &info); void slotNoStatusFound(QNetworkReply *reply); - void slotJobTimeout(const QUrl &url); void slotAuthFailed(QNetworkReply *reply); void slotAuthSuccess(); diff --git a/src/libsync/abstractnetworkjob.cpp b/src/libsync/abstractnetworkjob.cpp index dce36887f..c77c4b905 100644 --- a/src/libsync/abstractnetworkjob.cpp +++ b/src/libsync/abstractnetworkjob.cpp @@ -336,13 +336,13 @@ void AbstractNetworkJob::start() const QString displayUrl = QStringLiteral("%1://%2%3").arg(url.scheme()).arg(url.host()).arg(url.path()); QByteArray parentMetaObjectName = parent() ? parent()->metaObject()->className() : QByteArray(); - qCInfo(lcNetworkJob) << metaObject()->className() << "created for" << displayUrl << "+" << path() << parentMetaObjectName; + qCInfo(lcNetworkJob) << this << "created for" << displayUrl << "+" << path() << parentMetaObjectName; } void AbstractNetworkJob::slotTimeout() { _timedout = true; - qCWarning(lcNetworkJob) << "Network job timeout" << (reply() ? reply()->request().url().path() : path()); + qCWarning(lcNetworkJob) << "Network job" << this << "timeout"; onTimedOut(); } @@ -451,14 +451,22 @@ QDebug operator<<(QDebug debug, const OCC::AbstractNetworkJob *job) { QDebugStateSaver saver(debug); debug.setAutoInsertSpaces(false); - debug << job->metaObject()->className() << "(" << job->url().toString(); + debug << job->metaObject()->className() << "(" << job->url().toDisplayString(); if (auto reply = job->reply()) { debug << ", " << reply->request().rawHeader("Original-Request-ID") << ", " << reply->request().rawHeader("X-Request-ID"); + + const auto errorString = reply->rawHeader(QByteArrayLiteral("OC-ErrorString")); + if (!errorString.isEmpty()) { + debug << ", " << errorString; + } if (reply->error() != QNetworkReply::NoError) { debug << ", " << reply->errorString(); } } + if (job->_timedout) { + debug << ", timedout"; + } debug << ")"; return debug.maybeSpace(); } diff --git a/src/libsync/abstractnetworkjob.h b/src/libsync/abstractnetworkjob.h index 2084638fe..0de60a1f0 100644 --- a/src/libsync/abstractnetworkjob.h +++ b/src/libsync/abstractnetworkjob.h @@ -32,6 +32,9 @@ class QUrl; + +OWNCLOUDSYNC_EXPORT QDebug operator<<(QDebug debug, const OCC::AbstractNetworkJob *job); + namespace OCC { class AbstractSslErrorHandler; @@ -192,6 +195,8 @@ private: bool _isAuthenticationJob = false; int _retryCount = 0; + + friend QDebug(::operator<<)(QDebug debug, const AbstractNetworkJob *job); }; /** @@ -233,5 +238,3 @@ QString OWNCLOUDSYNC_EXPORT networkReplyErrorString(const QNetworkReply &reply); } // namespace OCC - -OWNCLOUDSYNC_EXPORT QDebug operator<<(QDebug debug, const OCC::AbstractNetworkJob *job); |