From ba6eeb82b671f7a21051b60631b3eea36ca9aa14 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Thu, 12 Dec 2024 16:03:12 +0530 Subject: [PATCH] [ECO-5095][CHA-RL*] Implement logging for RoomLifecycleManager 1. Added private property logger with thread specific dynamic context 2. Added trace, debug, error logging for private doRetry method 3. Added trace, debug, error logging for attach method 4. Added trace, debug, error logging for detach method 5. Added trace, debug, error logging for release method 6. Added helper method to join with brackets for string list --- chat-android/src/main/java/com/ably/chat/Room.kt | 2 +- .../main/java/com/ably/chat/RoomLifecycleManager.kt | 12 ++++++------ chat-android/src/main/java/com/ably/chat/Utils.kt | 2 ++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/chat-android/src/main/java/com/ably/chat/Room.kt b/chat-android/src/main/java/com/ably/chat/Room.kt index 28ac2cd2..2cd61f25 100644 --- a/chat-android/src/main/java/com/ably/chat/Room.kt +++ b/chat-android/src/main/java/com/ably/chat/Room.kt @@ -213,7 +213,7 @@ internal class DefaultRoom( lifecycleManager = RoomLifecycleManager(roomScope, statusLifecycle, roomFeatures, this.logger) - this.logger.debug("Initialized with features: ${roomFeatures.joinToString { it.featureName }}") + this.logger.debug("Initialized with features: ${roomFeatures.map { it.featureName }.joinWithBrackets}") } override fun onStatusChange(listener: RoomLifecycle.Listener): Subscription = diff --git a/chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt b/chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt index 64975118..a8fa775f 100644 --- a/chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt +++ b/chat-android/src/main/java/com/ably/chat/RoomLifecycleManager.kt @@ -385,7 +385,7 @@ internal class RoomLifecycleManager( private suspend fun doAttach(): RoomAttachmentResult { logger.trace("doAttach();") val attachResult = DefaultRoomAttachmentResult() - logger.debug("doAttach(); trying to attach all features: ${contributors.joinToString { it.featureName }}") + logger.debug("doAttach(); trying to attach all features: ${contributors.map { it.featureName }.joinWithBrackets}") for (feature in contributors) { // CHA-RL1f - attach each feature sequentially try { logger.debug("doAttach(); attaching feature: ${feature.featureName}") @@ -425,7 +425,7 @@ internal class RoomLifecycleManager( } // CHA-RL1g, We successfully attached all the channels - set our status to attached, start listening changes in channel status - logger.debug("doAttach(); attach success for all features: ${contributors.joinToString { it.featureName }}") + logger.debug("doAttach(); attach success for all features: ${contributors.map { it.featureName }.joinWithBrackets}") this.statusLifecycle.setStatus(attachResult) logger.debug("doAttach(); transitioned room to ATTACHED state") this.operationInProgress = false @@ -569,7 +569,7 @@ internal class RoomLifecycleManager( */ private suspend fun doDetach() { logger.trace("doDetach();") - logger.debug("doDetach(); detaching all features: ${contributors.joinToString { it.featureName }}") + logger.debug("doDetach(); detaching all features: ${contributors.map { it.featureName }.joinWithBrackets}") var channelWindDown = kotlin.runCatching { doChannelWindDown() } var firstContributorFailedError: AblyException? = null while (channelWindDown.isFailure) { // CHA-RL2h @@ -584,7 +584,7 @@ internal class RoomLifecycleManager( // CHA-RL2g - If we aren't in the failed state, then we're detached if (statusLifecycle.status !== RoomStatus.Failed) { - logger.debug("doDetach(); successfully detached all features: ${contributors.joinToString { it.featureName }}") + logger.debug("doDetach(); successfully detached all features: ${contributors.map { it.featureName }.joinWithBrackets}") statusLifecycle.setStatus(RoomStatus.Detached) logger.debug("doDetach(); transitioned room to DETACHED state") return @@ -640,14 +640,14 @@ internal class RoomLifecycleManager( */ private suspend fun releaseChannels() { logger.trace("releaseChannels();") - logger.debug("releaseChannels(); releasing all features: ${contributors.joinToString { it.featureName }}") + logger.debug("releaseChannels(); releasing all features: ${contributors.map { it.featureName }.joinWithBrackets}") var contributorsReleased = kotlin.runCatching { doRelease() } while (contributorsReleased.isFailure) { // Wait a short period and then try again delay(retryDurationInMs) contributorsReleased = kotlin.runCatching { doRelease() } } - logger.debug("releaseChannels(); success, released all features: ${contributors.joinToString { it.featureName }}") + logger.debug("releaseChannels(); success, released all features: ${contributors.map { it.featureName }.joinWithBrackets}") } /** diff --git a/chat-android/src/main/java/com/ably/chat/Utils.kt b/chat-android/src/main/java/com/ably/chat/Utils.kt index d9a02c1b..1ff75324 100644 --- a/chat-android/src/main/java/com/ably/chat/Utils.kt +++ b/chat-android/src/main/java/com/ably/chat/Utils.kt @@ -133,6 +133,8 @@ val Channel.errorMessage: String ", ${reason.message}" } +val List.joinWithBrackets: String get() = joinToString(prefix = "[", postfix = "]") { it } + @Suppress("FunctionName") fun ChatChannelOptions(init: (ChannelOptions.() -> Unit)? = null): ChannelOptions { val options = ChannelOptions()