refactor: move logs to timber
This commit is contained in:
+11
-11
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user