diff --git a/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloader.kt b/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloader.kt index 7c011a470..fe6d7617f 100644 --- a/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloader.kt +++ b/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloader.kt @@ -132,7 +132,7 @@ public class HttpDownloader constructor( // calculatedEtag == expectedETag (ETag calculated from server response matches expected ETag) if (!headInfo.eTagChanged || calculatedEtag == expectedETag) { // ETag has not changed, don't download again - log.info { "${request.indexFile.name} cached, not downloading." } + log.debug { "${request.indexFile.name} cached, not downloading." } hasChanged = false return } @@ -145,24 +145,20 @@ public class HttpDownloader constructor( var resumable = false val fileLength = outputFile.length() if (fileLength > (fileSize ?: -1)) { - if (!outputFile.delete()) log.warn { - "Warning: " + outputFile.absolutePath + " not deleted" - } + if (!outputFile.delete()) log.warn { "Warning: outputFile not deleted" } } else if (fileLength == fileSize && outputFile.isFile) { - log.info { "Already have outputFile, not download. ${outputFile.absolutePath}" } + log.debug { "Already have outputFile, not downloading: ${outputFile.name}" } return // already have it! } else if (fileLength > 0) { resumable = true } - log.info { "downloading ${request.indexFile.name} (is resumable: $resumable)" } + log.debug { "Downloading ${request.indexFile.name} (is resumable: $resumable)" } runBlocking { try { downloadFromBytesReceiver(resumable) } catch (e: NoResumeException) { require(resumable) { "Got $e even though download was not resumable" } - if (!outputFile.delete()) log.warn { - "Warning: " + outputFile.absolutePath + " not deleted" - } + if (!outputFile.delete()) log.warn { "Warning: outputFile not deleted" } downloadFromBytesReceiver(false) } } diff --git a/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloaderV2.kt b/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloaderV2.kt index b3c283333..f99445213 100644 --- a/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloaderV2.kt +++ b/libs/download/src/androidMain/kotlin/org/fdroid/download/HttpDownloaderV2.kt @@ -62,24 +62,20 @@ public class HttpDownloaderV2 constructor( var resumable = false val fileLength = outputFile.length() if (fileLength > (request.indexFile.size ?: -1)) { - if (!outputFile.delete()) log.warn { - "Warning: " + outputFile.absolutePath + " not deleted" - } + if (!outputFile.delete()) log.warn { "Warning: outputFile not deleted" } } else if (fileLength == request.indexFile.size && outputFile.isFile) { - log.info { "Already have outputFile, not download. ${outputFile.absolutePath}" } + log.debug { "Already have outputFile, not downloading: ${outputFile.name}" } return // already have it! } else if (fileLength > 0) { resumable = true } - log.info { "downloading ${request.indexFile.name} (is resumable: $resumable)" } + log.debug { "Downloading ${request.indexFile.name} (is resumable: $resumable)" } runBlocking { try { downloadFromBytesReceiver(resumable) } catch (e: NoResumeException) { require(resumable) { "Got $e even though download was not resumable" } - if (!outputFile.delete()) log.warn { - "Warning: " + outputFile.absolutePath + " not deleted" - } + if (!outputFile.delete()) log.warn { "Warning: outputFile not deleted" } downloadFromBytesReceiver(false) } } diff --git a/libs/download/src/androidMain/kotlin/org/fdroid/download/glide/HttpGlideUrlLoader.kt b/libs/download/src/androidMain/kotlin/org/fdroid/download/glide/HttpGlideUrlLoader.kt index 5eef32f50..52df5683e 100644 --- a/libs/download/src/androidMain/kotlin/org/fdroid/download/glide/HttpGlideUrlLoader.kt +++ b/libs/download/src/androidMain/kotlin/org/fdroid/download/glide/HttpGlideUrlLoader.kt @@ -31,7 +31,8 @@ public class HttpGlideUrlLoader( height: Int, options: Options, ): LoadData { - log.warn { "Not using mirrors when loading $glideUrl" } + if (log.isDebugEnabled) log.warn { "Not using mirrors when loading $glideUrl" } + else log.warn { "Not using mirrors for load" } return LoadData(glideUrl, HttpFetcher(httpManager, glideUrl, proxyGetter())) } diff --git a/libs/download/src/commonMain/kotlin/org/fdroid/download/HttpManager.kt b/libs/download/src/commonMain/kotlin/org/fdroid/download/HttpManager.kt index e5eba4eea..2951a7e0f 100644 --- a/libs/download/src/commonMain/kotlin/org/fdroid/download/HttpManager.kt +++ b/libs/download/src/commonMain/kotlin/org/fdroid/download/HttpManager.kt @@ -96,7 +96,7 @@ public open class HttpManager @JvmOverloads constructor( val response: HttpResponse = try { mirrorChooser.mirrorRequest(request) { mirror, url -> resetProxyIfNeeded(request.proxy, mirror) - log.info { "HEAD $url" } + log.debug { "HEAD $url" } httpClient.head(url) { addQueryParameters() // add authorization header from username / password if set @@ -106,7 +106,7 @@ public open class HttpManager @JvmOverloads constructor( } } } catch (e: ResponseException) { - log.warn(e) { "Error getting HEAD" } + log.warn { "Error getting HEAD: ${e.response.status}" } if (e.response.status == NotFound) throw NotFoundException() return null } @@ -153,7 +153,7 @@ public open class HttpManager @JvmOverloads constructor( skipFirstBytes: Long, ): HttpStatement { resetProxyIfNeeded(request.proxy, mirror) - log.info { "GET $url" } + log.debug { "GET $url" } return httpClient.prepareGet(url) { addQueryParameters() // add authorization header from username / password if set @@ -209,13 +209,13 @@ public open class HttpManager @JvmOverloads constructor( private fun resetProxyIfNeeded(proxyConfig: ProxyConfig?, mirror: Mirror? = null) { // force no-proxy when trying to hit a local mirror val newProxy = if (mirror.isLocal() && proxyConfig != null) { - if (currentProxy != null) log.info { + if (currentProxy != null) log.debug { "Forcing mirror to null, because mirror is local: $mirror" } null } else proxyConfig if (currentProxy != newProxy) { - log.info { "Switching proxy from [$currentProxy] to [$newProxy]" } + log.debug { "Switching proxy from [$currentProxy] to [$newProxy]" } httpClient.close() httpClient = getNewHttpClient(newProxy) } diff --git a/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt b/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt index 41227e5e4..3c25a3ce0 100644 --- a/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt +++ b/libs/download/src/commonMain/kotlin/org/fdroid/download/MirrorChooser.kt @@ -68,9 +68,11 @@ internal abstract class MirrorChooserImpl : MirrorChooser { } private fun throwOnLastMirror(e: Exception, wasLastMirror: Boolean) { - log.warn(e) { - if (wasLastMirror) "Last mirror, rethrowing..." - else "Trying other mirror now..." + log.info { + val info = if (e is ResponseException) e.response.status.toString() + else e::class.simpleName ?: "" + if (wasLastMirror) "Last mirror, rethrowing... ($info)" + else "Trying other mirror now... ($info)" } if (wasLastMirror) throw e }