refactor: move logs to timber

This commit is contained in:
2026-06-08 19:07:09 +02:00
parent ceed94b253
commit f4b74ee43d
37 changed files with 267 additions and 258 deletions
@@ -1,7 +1,7 @@
package com.bitcointxoko.gudariwallet.service
import android.content.Context
import android.util.Log
import timber.log.Timber
import com.bitcointxoko.gudariwallet.api.NodeAliasClient as NodeAliasApiClient
import com.bitcointxoko.gudariwallet.data.NodeAliasCacheRepository
import kotlinx.coroutines.flow.MutableStateFlow
@@ -26,14 +26,14 @@ class NodeAliasService(
suspend fun resolve(pubkey: String): String? {
// 1. Room cache hit
repo.get(pubkey)?.let {
Log.d(TAG, "ALIAS [CACHE HIT ] $pubkey\"$it\"")
Timber.d("ALIAS [CACHE HIT ] $pubkey\"$it\"")
return it
}
// 2. Network via api/NodeAliasService (Retrofit, typed responses)
Log.d(TAG, "ALIAS [CACHE MISS] $pubkey — fetching from network")
Timber.d("ALIAS [CACHE MISS] $pubkey — fetching from network")
val alias = apiClient.resolveAlias(pubkey) ?: run {
Log.w(TAG, "ALIAS [NOT FOUND ] $pubkey")
Timber.w("ALIAS [NOT FOUND ] $pubkey")
return null
}
@@ -43,7 +43,7 @@ class NodeAliasService(
// 4. Publish to StateFlow
_aliases.value = _aliases.value + (pubkey to alias)
Log.d(TAG, "ALIAS [FETCHED ] $pubkey\"$alias\"")
Timber.d("ALIAS [FETCHED ] $pubkey\"$alias\"")
return alias
}
@@ -6,7 +6,7 @@ import android.content.Intent
import android.content.pm.ServiceInfo
import android.os.Build
import android.os.IBinder
import android.util.Log
import timber.log.Timber
import com.bitcointxoko.gudariwallet.api.GsonProvider
import com.bitcointxoko.gudariwallet.api.LNbitsClient
import com.bitcointxoko.gudariwallet.api.PaymentRecord
@@ -124,7 +124,7 @@ class WalletNotificationService : Service() {
override fun onDestroy() {
super.onDestroy()
Log.d(TAG, "Service destroyed — closing WebSocket")
Timber.d("Service destroyed — closing WebSocket")
reconnectJob?.cancel()
webSocket?.close(WalletConstants.WS_CLOSE_NORMAL, "Service stopped")
webSocket = null
@@ -143,7 +143,7 @@ class WalletNotificationService : Service() {
val baseUrl = secrets.baseUrl()
if (invoiceKey.isBlank() || baseUrl.isBlank()) {
Log.e(TAG, "Credentials not available — cannot open WebSocket")
Timber.e("Credentials not available — cannot open WebSocket")
stopSelf()
return
}
@@ -153,36 +153,36 @@ class WalletNotificationService : Service() {
.replace("http://", "ws://")
.trimEnd('/') + "/api/v1/ws/${invoiceKey}"
Log.d(TAG, "Opening WebSocket: $wsUrl")
Timber.d("Opening WebSocket: $wsUrl")
val request = Request.Builder().url(wsUrl).build()
webSocket = LNbitsClient.httpClient.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {
Log.d(TAG, "WebSocket connected")
Timber.d("WebSocket connected")
// Reset backoff on successful connection
reconnectAttempts = 0
currentBackoffMs = WalletConstants.WS_INITIAL_BACKOFF_MS
}
override fun onMessage(webSocket: WebSocket, text: String) {
Log.d(TAG, "WebSocket message: $text")
Timber.d("WebSocket message: $text")
handleMessage(text)
}
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
Log.e(TAG, "WebSocket failure (attempt $reconnectAttempts): ${t.message}")
Timber.e("WebSocket failure (attempt $reconnectAttempts): ${t.message}")
scheduleReconnect()
}
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
Log.d(TAG, "WebSocket closing: $code $reason")
Timber.d("WebSocket closing: $code $reason")
webSocket.close(WalletConstants.WS_CLOSE_NORMAL, null)
}
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
Log.d(TAG, "WebSocket closed: $code $reason")
Timber.d("WebSocket closed: $code $reason")
// Only reconnect on unexpected closes (not our own WS_CLOSE_NORMAL)
if (code != WalletConstants.WS_CLOSE_NORMAL) {
scheduleReconnect()
@@ -257,7 +257,7 @@ class WalletNotificationService : Service() {
private fun scheduleReconnect() {
if (reconnectAttempts >= WalletConstants.WS_MAX_ATTEMPTS) {
Log.e(TAG, "WebSocket gave up after ${WalletConstants.WS_MAX_ATTEMPTS} attempts — service will wait for next start")
Timber.e("WebSocket gave up after ${WalletConstants.WS_MAX_ATTEMPTS} attempts — service will wait for next start")
// Do not stop the service — it will reconnect on next onStartCommand
// (e.g. when the app is brought to foreground and MainActivity calls start())
return
@@ -267,7 +267,7 @@ class WalletNotificationService : Service() {
reconnectAttempts++
currentBackoffMs = (currentBackoffMs * 2).coerceAtMost(WalletConstants.WS_MAX_BACKOFF_MS)
Log.d(TAG, "Reconnecting in ${backoff}ms (attempt $reconnectAttempts of ${WalletConstants.WS_MAX_ATTEMPTS})")
Timber.d("Reconnecting in ${backoff}ms (attempt $reconnectAttempts of ${WalletConstants.WS_MAX_ATTEMPTS})")
reconnectJob?.cancel()
reconnectJob = serviceScope.launch {