Skip to content

Commit b9317ee

Browse files
committed
Add log tag
1 parent d323148 commit b9317ee

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/DefaultNotificationDrawerManager.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import io.element.android.libraries.androidutils.throttler.FirstThrottler
2020
import io.element.android.libraries.core.cache.CircularCache
2121
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
2222
import io.element.android.libraries.core.data.tryOrNull
23+
import io.element.android.libraries.core.log.logger.LoggerTag
2324
import io.element.android.libraries.core.meta.BuildMeta
2425
import io.element.android.libraries.di.AppScope
2526
import io.element.android.libraries.di.SingleIn
@@ -30,6 +31,7 @@ import io.element.android.libraries.matrix.api.core.SessionId
3031
import io.element.android.libraries.matrix.api.core.ThreadId
3132
import io.element.android.libraries.matrix.api.user.MatrixUser
3233
import io.element.android.libraries.push.api.notifications.NotificationDrawerManager
34+
import io.element.android.libraries.push.impl.log.notificationLoggerTag
3335
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
3436
import io.element.android.services.appnavstate.api.AppNavigationStateService
3537
import io.element.android.services.appnavstate.api.NavigationState
@@ -41,6 +43,8 @@ import kotlinx.coroutines.withContext
4143
import timber.log.Timber
4244
import javax.inject.Inject
4345

46+
private val loggerTag = LoggerTag("DefaultNotificationDrawerManager", notificationLoggerTag)
47+
4448
/**
4549
* The NotificationDrawerManager receives notification events as they arrived (from event stream or fcm) and
4650
* organise them in order to display them in the notification drawer.
@@ -116,13 +120,13 @@ class DefaultNotificationDrawerManager @Inject constructor(
116120

117121
private fun NotificationEventQueue.onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
118122
if (buildMeta.lowPrivacyLoggingEnabled) {
119-
Timber.d("onNotifiableEventReceived(): $notifiableEvent")
123+
Timber.tag(loggerTag.value).d("onNotifiableEventReceived(): $notifiableEvent")
120124
} else {
121-
Timber.d("onNotifiableEventReceived(): is push: ${notifiableEvent.canBeReplaced}")
125+
Timber.tag(loggerTag.value).d("onNotifiableEventReceived(): is push: ${notifiableEvent.canBeReplaced}")
122126
}
123127

124128
if (filteredEventDetector.shouldBeIgnored(notifiableEvent)) {
125-
Timber.d("onNotifiableEventReceived(): ignore the event")
129+
Timber.tag(loggerTag.value).d("onNotifiableEventReceived(): ignore the event")
126130
return
127131
}
128132

@@ -233,28 +237,28 @@ class DefaultNotificationDrawerManager @Inject constructor(
233237
private fun CoroutineScope.refreshNotificationDrawer(doRender: Boolean) = launch {
234238
// Implement last throttler
235239
val canHandle = firstThrottler.canHandle()
236-
Timber.v("refreshNotificationDrawer($doRender), delay: ${canHandle.waitMillis()} ms")
240+
Timber.tag(loggerTag.value).v("refreshNotificationDrawer($doRender), delay: ${canHandle.waitMillis()} ms")
237241
withContext(dispatchers.io) {
238242
delay(canHandle.waitMillis())
239243
try {
240244
refreshNotificationDrawerBg(doRender)
241245
} catch (throwable: Throwable) {
242246
// It can happen if for instance session has been destroyed. It's a bit ugly to try catch like this, but it's safer
243-
Timber.w(throwable, "refreshNotificationDrawerBg failure")
247+
Timber.tag(loggerTag.value).w(throwable, "refreshNotificationDrawerBg failure")
244248
}
245249
}
246250
}
247251

248252
private suspend fun refreshNotificationDrawerBg(doRender: Boolean) {
249-
Timber.v("refreshNotificationDrawerBg($doRender)")
253+
Timber.tag(loggerTag.value).v("refreshNotificationDrawerBg($doRender)")
250254
val eventsToRender = notificationState.updateQueuedEvents { queuedEvents, renderedEvents ->
251255
notifiableEventProcessor.process(queuedEvents.rawEvents(), renderedEvents).also {
252256
queuedEvents.clearAndAdd(it.onlyKeptEvents())
253257
}
254258
}
255259

256260
if (notificationState.hasAlreadyRendered(eventsToRender)) {
257-
Timber.d("Skipping notification update due to event list not changing")
261+
Timber.tag(loggerTag.value).d("Skipping notification update due to event list not changing")
258262
} else {
259263
notificationState.clearAndAddRenderedEvents(eventsToRender)
260264
if (doRender) {
@@ -278,7 +282,7 @@ class DefaultNotificationDrawerManager @Inject constructor(
278282

279283
eventsForSessions.forEach { (sessionId, notifiableEvents) ->
280284
val currentUser = tryOrNull(
281-
onError = { Timber.e(it, "Unable to retrieve info for user ${sessionId.value}") },
285+
onError = { Timber.tag(loggerTag.value).e(it, "Unable to retrieve info for user ${sessionId.value}") },
282286
operation = {
283287
val client = matrixClientProvider.getOrRestore(sessionId).getOrThrow()
284288
// myUserDisplayName cannot be empty else NotificationCompat.MessagingStyle() will crash

0 commit comments

Comments
 (0)