From c47713b1057d5f1131dd335142d242bab5a62d29 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 30 Dec 2024 13:20:06 +0100 Subject: [PATCH] Fix issue with logger. --- .../unifiedpush/UnifiedPushGatewayResolver.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt index 51f9703fe0..0af1d62e7d 100644 --- a/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt +++ b/libraries/pushproviders/unifiedpush/src/main/kotlin/io/element/android/libraries/pushproviders/unifiedpush/UnifiedPushGatewayResolver.kt @@ -34,40 +34,38 @@ class DefaultUnifiedPushGatewayResolver @Inject constructor( private val unifiedPushApiFactory: UnifiedPushApiFactory, private val coroutineDispatchers: CoroutineDispatchers, ) : UnifiedPushGatewayResolver { - private val logger = Timber.tag("DefaultUnifiedPushGatewayResolver") - override suspend fun getGateway(endpoint: String): UnifiedPushGatewayResolverResult { val url = tryOrNull( - onError = { logger.d(it, "Cannot parse endpoint as an URL") } + onError = { Timber.tag("DefaultUnifiedPushGatewayResolver").d(it, "Cannot parse endpoint as an URL") } ) { URL(endpoint) } return if (url == null) { - logger.d("Using default gateway") + Timber.tag("DefaultUnifiedPushGatewayResolver").d("ErrorInvalidUrl") UnifiedPushGatewayResolverResult.ErrorInvalidUrl } else { val port = if (url.port != -1) ":${url.port}" else "" val customBase = "${url.protocol}://${url.host}$port" val customUrl = "$customBase/_matrix/push/v1/notify" - logger.i("Testing $customUrl") + Timber.tag("DefaultUnifiedPushGatewayResolver").i("Testing $customUrl") return withContext(coroutineDispatchers.io) { val api = unifiedPushApiFactory.create(customBase) try { val discoveryResponse = api.discover() if (discoveryResponse.unifiedpush.gateway == "matrix") { - logger.d("The endpoint seems to be a valid UnifiedPush gateway") + Timber.tag("DefaultUnifiedPushGatewayResolver").d("The endpoint seems to be a valid UnifiedPush gateway") UnifiedPushGatewayResolverResult.Success(customUrl) } else { // The endpoint returned a 200 OK but didn't promote an actual matrix gateway, which means it doesn't have any - logger.w("The endpoint does not seem to be a valid UnifiedPush gateway, using fallback") + Timber.tag("DefaultUnifiedPushGatewayResolver").w("The endpoint does not seem to be a valid UnifiedPush gateway, using fallback") UnifiedPushGatewayResolverResult.NoMatrixGateway } } catch (throwable: Throwable) { if ((throwable as? HttpException)?.code() == HttpURLConnection.HTTP_NOT_FOUND) { - logger.i("Checking for UnifiedPush endpoint yielded 404, using fallback") + Timber.tag("DefaultUnifiedPushGatewayResolver").i("Checking for UnifiedPush endpoint yielded 404, using fallback") UnifiedPushGatewayResolverResult.NoMatrixGateway } else { - logger.e(throwable, "Error checking for UnifiedPush endpoint") + Timber.tag("DefaultUnifiedPushGatewayResolver").e(throwable, "Error checking for UnifiedPush endpoint") UnifiedPushGatewayResolverResult.Error(customUrl) } }