From 79795af7233aaf160d0c540023292798e28a0d20 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 4 Sep 2024 11:12:21 +0200 Subject: [PATCH] Imporve logs. --- .../unifiedpush/UnifiedPushGatewayResolver.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 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 ff04d007ab..9190560b70 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,29 +34,33 @@ 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): String { val url = tryOrNull( - onError = { Timber.d(it, "Cannot parse endpoint as an URL") } + onError = { logger.d(it, "Cannot parse endpoint as an URL") } ) { URL(endpoint) } return if (url == null) { - Timber.d("Using default gateway") + logger.d("Using default gateway") UnifiedPushConfig.DEFAULT_PUSH_GATEWAY_HTTP_URL } else { val port = if (url.port != -1) ":${url.port}" else "" val customBase = "${url.protocol}://${url.host}$port" val customUrl = "$customBase/_matrix/push/v1/notify" - Timber.i("Testing $customUrl") + logger.i("Testing $customUrl") return withContext(coroutineDispatchers.io) { val api = unifiedPushApiFactory.create(customBase) try { val discoveryResponse = api.discover() if (discoveryResponse.unifiedpush.gateway == "matrix") { - Timber.d("Using custom gateway") + logger.d("The endpoint seems to be a valid UnifiedPush gateway") + } else { + logger.e("The endpoint does not seem to be a valid UnifiedPush gateway") } } catch (throwable: Throwable) { - Timber.tag("UnifiedPushHelper").e(throwable) + logger.e(throwable, "Error checking for UnifiedPush endpoint") } // Always return the custom url. customUrl