Skip to content

Commit

Permalink
[ECO-5095][CHA-RL*] Implement logging for RoomLifecycleManager
Browse files Browse the repository at this point in the history
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. Refactored Logger.kt default Android Logger TAG and formattedMessage a bit
  • Loading branch information
sacOO7 committed Dec 12, 2024
1 parent 11180ae commit 037d607
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 47 deletions.
4 changes: 2 additions & 2 deletions chat-android/src/main/java/com/ably/chat/Logger.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ internal class AndroidLogger(
override fun log(message: String, level: LogLevel, throwable: Throwable?, newTag: String?, newStaticContext: Map<String, String>) {
if (level.logLevelValue < minimalVisibleLogLevel.logLevelValue) return
val finalContext = context.mergeWith(newTag, newStaticContext)
val tag = finalContext.tag
val tag = "ably-chat:${finalContext.tag}"
val completeContext = finalContext.staticContext + finalContext.dynamicContext.mapValues { it.value() }

val contextString = ", context: $completeContext"
val currentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S", Locale.US).format(Date())
val formattedMessage = "$currentTime [$tag] (${level.name.uppercase()}) ably-chat: ${message}$contextString"
val formattedMessage = "$currentTime (${level.name.uppercase()}) ${finalContext.tag}:${message}$contextString"
when (level) {
// We use Logcat's info level for Trace and Debug
LogLevel.Trace -> Log.i(tag, formattedMessage, throwable)
Expand Down
2 changes: 1 addition & 1 deletion chat-android/src/main/java/com/ably/chat/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Loading

0 comments on commit 037d607

Please sign in to comment.