Refactor logging

refactor(logging): move the last android.util.Log users onto the quartz wrapper
fix(logging): use the lambda overload, and keep the throwable in a catch log
This commit is contained in:
davotoula
2026-08-28 19:27:46 +02:00
parent 8293cbfb7f
commit ccdcf433e1
25 changed files with 33 additions and 33 deletions
@@ -21,12 +21,12 @@
package com.vitorpamplona.amethyst.favorites
import android.content.Context
import android.util.Log
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.vitorpamplona.amethyst.commons.browser.OmniboxInput
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -21,7 +21,7 @@
package com.vitorpamplona.amethyst.favorites
import android.content.Context
import android.util.Log
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -24,7 +24,6 @@ import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.R
@@ -41,6 +40,7 @@ import com.vitorpamplona.quartz.nip5aStaticWebsites.NamedSiteEvent
import com.vitorpamplona.quartz.nip5aStaticWebsites.RootSiteEvent
import com.vitorpamplona.quartz.nip5dNapplets.NamedNappletEvent
import com.vitorpamplona.quartz.nip5dNapplets.RootNappletEvent
import com.vitorpamplona.quartz.utils.Log
/**
* Turns a [FavoriteApp] back into a running app. The two cases map to the two launch paths in the
@@ -145,7 +145,7 @@ object FavoriteAppLauncher {
profile = HostProfile.WEBSITE,
)
else -> {
Log.w("FavoriteAppLauncher", "Favorited app not resolvable yet: $coordinate")
Log.w("FavoriteAppLauncher") { "Favorited app not resolvable yet: $coordinate" }
Toast.makeText(context, R.string.favorite_app_still_loading, Toast.LENGTH_SHORT).show()
}
}
@@ -21,12 +21,12 @@
package com.vitorpamplona.amethyst.favorites
import android.content.Context
import android.util.Log
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.vitorpamplona.amethyst.commons.favorites.FavoriteApp
import com.vitorpamplona.quartz.nip01Core.core.JsonMapper
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
@@ -1381,7 +1381,7 @@ class AccountConcordActions(
val bannedHere = authority.isBanned(account.signer.pubKey)
val merged = ConcordActions.recoverStranded(entry, bundle, bannedHere) ?: continue
if (!adoptedConcordRotations.add("${entry.id}:${merged.rootEpoch}")) continue
Log.i("Concord", "Stranded recovery: ${entry.id} ${entry.rootEpoch} -> ${merged.rootEpoch}")
Log.i("Concord") { "Stranded recovery: ${entry.id} ${entry.rootEpoch} -> ${merged.rootEpoch}" }
account.sendMyPublicAndPrivateOutbox(account.concordChannelList.follow(merged))
announceConcordGuestbookJoin(merged, inviteCreator = null, inviteLabel = null)
}
@@ -1600,6 +1600,6 @@ class AccountConcordActions(
val byRelay = authorsByRelay.mapValues { (_, authors) -> listOf(ConcordActions.planeFilterFor(authors.toList())) }
var drained = 0
account.client.fetchAllPagesFromPool(filters = byRelay) { _, _ -> drained++ }
Log.d("Concord", "syncConcordControlPlanes: paged ${authorsByRelay.size} relay(s), drained $drained control wrap(s)")
Log.d("Concord") { "syncConcordControlPlanes: paged ${authorsByRelay.size} relay(s), drained $drained control wrap(s)" }
}
}
@@ -147,7 +147,7 @@ class AccountCacheState(
fun deleteAccountFiles(pubkey: HexKey) {
val dir = File(accountsRootDir(), pubkey)
if (dir.exists() && !dir.deleteRecursively()) {
Log.w("AccountCacheState", "Failed to delete account directory ${dir.absolutePath}")
Log.w("AccountCacheState") { "Failed to delete account directory ${dir.absolutePath}" }
}
}
@@ -163,7 +163,7 @@ class AccountCacheState(
if (child.deleteRecursively()) {
Log.d("AccountCacheState") { "Pruned orphan account dir ${child.name.take(8)}…" }
} else {
Log.w("AccountCacheState", "Failed to prune orphan account dir ${child.absolutePath}")
Log.w("AccountCacheState") { "Failed to prune orphan account dir ${child.absolutePath}" }
}
}
}
@@ -31,7 +31,6 @@ import android.os.Message
import android.os.Messenger
import android.os.RemoteException
import android.os.SystemClock
import android.util.Log
import androidx.core.net.toUri
import com.vitorpamplona.amethyst.Amethyst
import com.vitorpamplona.amethyst.commons.connectedApps.signers.NostrSignerPermissionLedger
@@ -50,6 +49,7 @@ import com.vitorpamplona.amethyst.napplet.gateways.AccountNappletGateways
import com.vitorpamplona.amethyst.napplethost.NappletIpc
import com.vitorpamplona.amethyst.ui.MainActivity
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineStart
import kotlinx.coroutines.Dispatchers
@@ -182,7 +182,7 @@ class NappletBrokerService : Service() {
// could still spam distinct keys to keep the network up. Bound the damage: refuse new
// lease keys past the cap. Real usage holds only a handful of foreground surfaces.
if (firstReport && foregroundLeases.size >= MAX_FOREGROUND_LEASES) {
Log.w("NappletBrokerService", "Foreground lease cap reached; ignoring new lease $token")
Log.w("NappletBrokerService") { "Foreground lease cap reached; ignoring new lease $token" }
return true
}
foregroundLeases[token] = SystemClock.elapsedRealtime()
@@ -374,7 +374,7 @@ class NappletBrokerService : Service() {
while (iterator.hasNext()) {
val entry = iterator.next()
if (now - entry.value > FOREGROUND_LEASE_TTL_MS) {
Log.w("NappletBrokerService", "Foreground lease ${entry.key} expired (host process gone?); releasing hold")
Log.w("NappletBrokerService") { "Foreground lease ${entry.key} expired (host process gone?); releasing hold" }
iterator.remove()
SandboxForegroundHold.release()
}
@@ -117,7 +117,7 @@ object SandboxForegroundHold {
synchronized(this@SandboxForegroundHold) {
// A surface may have re-acquired while we waited; only tear down if still released.
if (holdCount == 0) {
Log.d("SandboxForegroundHold", "No foreground sandbox surface for ${LINGER_MS}ms; releasing the resource hold")
Log.d("SandboxForegroundHold") { "No foreground sandbox surface for ${LINGER_MS}ms; releasing the resource hold" }
holdJob?.cancel()
holdJob = null
}
@@ -22,7 +22,7 @@ package com.vitorpamplona.amethyst.napplet
import android.content.Context
import android.content.Intent
import android.util.Log
import com.vitorpamplona.quartz.utils.Log
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
@@ -78,7 +78,7 @@ class MemoryTrimmingService(
level: Int = ComponentCallbacks2.TRIM_MEMORY_BACKGROUND,
) {
if (isTrimmingMemoryMutex.compareAndSet(false, true)) {
Log.d("ServiceManager", "Trimming Memory (level=$level)")
Log.d("ServiceManager") { "Trimming Memory (level=$level)" }
try {
doTrim(account, otherAccounts, level)
} finally {
@@ -222,7 +222,7 @@ class BootRelayDiagnostics(
r.closed.forEach { (k, v) -> closedTotals[k] = (closedTotals[k] ?: 0) + v.get() }
}
Log.d(TAG, "===== boot census @${atSeconds}s =====")
Log.d(TAG) { "===== boot census @${atSeconds}s =====" }
Log.i(
TAG,
"census @${atSeconds}s pool=${snapshot.size} opened=${opened.size} served_events=${served.size} never_opened=${neverOpened.size} " +
@@ -231,8 +231,8 @@ class BootRelayDiagnostics(
"reqs=${snapshot.values.sumOf { it.reqsSent.get() }} " +
"auths=${snapshot.values.sumOf { it.authsSent.get() }}",
)
Log.i(TAG, "census @${atSeconds}s failures_by_cause=" + causeTotals.entries.sortedByDescending { it.value }.joinToString { "${it.key}:${it.value}" })
Log.i(TAG, "census @${atSeconds}s closed_by_prefix=" + closedTotals.entries.sortedByDescending { it.value }.joinToString { "${it.key}:${it.value}" })
Log.i(TAG) { "census @${atSeconds}s failures_by_cause=" + causeTotals.entries.sortedByDescending { it.value }.joinToString { "${it.key}:${it.value}" } }
Log.i(TAG) { "census @${atSeconds}s closed_by_prefix=" + closedTotals.entries.sortedByDescending { it.value }.joinToString { "${it.key}:${it.value}" } }
// Relays that cost us dials and gave nothing back, worst first: the wasted-effort list.
Log.d(TAG, "--- top wasted dials (no events received) ---")
@@ -264,6 +264,6 @@ class BootRelayDiagnostics(
"openMs=${r.firstOpenAtMs.get()} eoseMs=${r.firstEoseAtMs.get()} dials=${r.tentatives.get()}",
)
}
Log.d(TAG, "===== end census @${atSeconds}s =====")
Log.d(TAG) { "===== end census @${atSeconds}s =====" }
}
}
@@ -153,7 +153,7 @@ object BlossomPaymentHandler {
val check = checkAmount(payment, shownSats)
if (check !is AmountCheck.Ok) {
Log.w("BlossomPayment", "refusing invoice: ${refusalReason(check)}")
Log.w("BlossomPayment") { "refusing invoice: ${refusalReason(check)}" }
return PayResult.Refused(refusalReason(check))
}
@@ -334,7 +334,7 @@ class BlossomBlobManagerViewModel : ViewModel() {
// again must not be able to spin up an endless pay-prompt
// cycle. One prompt per target per user-initiated mirror.
if (!promptLedger.shouldPrompt(row.hash, target)) {
Log.w("BlossomBlobManager", "mirror to $target asked for payment again after being paid; not re-prompting")
Log.w("BlossomBlobManager") { "mirror to $target asked for payment again after being paid; not re-prompting" }
_error.value = "${hostOf(target)} asked for payment again after being paid. Amethyst stopped to avoid paying twice."
continue
}
@@ -597,7 +597,7 @@ class CallSession(
val sender = videoSenders[key]
if (sender != null) {
if (!sender.setTrack(track, false)) {
Log.e(TAG, "Failed to replace video track for ${key.take(8)}")
Log.e(TAG) { "Failed to replace video track for ${key.take(8)}" }
}
} else {
session.addTrack(track, settingsProvider().callMaxBitrateBps)?.let { newSender ->
@@ -20,7 +20,6 @@
*/
package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.publicChannels.concord
import android.util.Log
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.PickVisualMediaRequest
@@ -80,6 +79,7 @@ import com.vitorpamplona.amethyst.ui.theme.MediumRelayIconModifier
import com.vitorpamplona.quartz.concord.cord02Community.ImagePointer
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.displayUrl
import com.vitorpamplona.quartz.utils.Log
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.launch
import com.vitorpamplona.amethyst.commons.icons.symbols.Icon as SymbolIcon
@@ -570,7 +570,7 @@ open class ChannelNewMessageViewModel :
accountViewModel.account.relayGroups.putRelayGroupUser(channel, pk, emptyList())
} catch (e: Exception) {
if (e is CancellationException) throw e
Log.w("BuzzAutoInvite", "Failed to add mentioned member ${pk.take(8)}: ${e.message}")
Log.w("BuzzAutoInvite", "Failed to add mentioned member ${pk.take(8)}", e)
}
}
}
@@ -20,7 +20,7 @@
*/
package com.vitorpamplona.amethyst.napplethost
import android.util.Log
import com.vitorpamplona.quartz.utils.Log
import okhttp3.OkHttpClient
import okhttp3.Request
import java.net.InetSocketAddress
@@ -33,7 +33,6 @@ import android.os.IBinder
import android.os.Looper
import android.os.Message
import android.os.Messenger
import android.util.Log
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
@@ -64,6 +63,7 @@ import androidx.webkit.WebViewCompat
import androidx.webkit.WebViewFeature
import com.vitorpamplona.amethyst.commons.browser.OmniboxInput
import com.vitorpamplona.amethyst.commons.napplet.NappletWebContract
import com.vitorpamplona.quartz.utils.Log
import org.json.JSONObject
import java.io.ByteArrayOutputStream
import java.lang.ref.WeakReference
@@ -36,7 +36,6 @@ import android.os.Looper
import android.os.Message
import android.os.Messenger
import android.os.SystemClock
import android.util.Log
import android.webkit.ConsoleMessage
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
@@ -56,6 +55,7 @@ import androidx.webkit.WebViewCompat
import androidx.webkit.WebViewFeature
import com.vitorpamplona.amethyst.commons.browser.OmniboxInput
import com.vitorpamplona.amethyst.commons.napplet.NappletWebContract
import com.vitorpamplona.quartz.utils.Log
import org.json.JSONObject
import java.io.ByteArrayOutputStream
@@ -23,8 +23,8 @@ package com.vitorpamplona.amethyst.napplethost
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.core.content.FileProvider
import com.vitorpamplona.quartz.utils.Log
import java.io.File
/**
@@ -23,9 +23,9 @@ package com.vitorpamplona.amethyst.napplethost
import android.os.Handler
import android.os.Looper
import android.util.Base64
import android.util.Log
import android.webkit.WebView
import com.vitorpamplona.amethyst.commons.browser.OmniboxInput
import com.vitorpamplona.quartz.utils.Log
import org.json.JSONObject
/**
@@ -33,7 +33,6 @@ import android.os.IBinder
import android.os.Looper
import android.os.Message
import android.os.Messenger
import android.util.Log
import android.util.TypedValue
import android.view.Gravity
import android.view.KeyEvent
@@ -69,6 +68,7 @@ import com.vitorpamplona.amethyst.napplethost.R
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip5aStaticWebsites.resolver.StaticSiteResolution
import com.vitorpamplona.quartz.nip5aStaticWebsites.tags.PathTag
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.sha256.sha256
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -36,7 +36,6 @@ import android.os.Looper
import android.os.Message
import android.os.Messenger
import android.os.SystemClock
import android.util.Log
import android.view.View
import android.webkit.JsPromptResult
import android.webkit.JsResult
@@ -61,6 +60,7 @@ import androidx.webkit.WebViewFeature
import com.vitorpamplona.amethyst.commons.napplet.NappletWebContract
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip5aStaticWebsites.tags.PathTag
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.quartz.utils.sha256.sha256
import org.json.JSONObject
import java.io.ByteArrayOutputStream
@@ -21,7 +21,6 @@
package com.vitorpamplona.amethyst.napplethost
import android.content.Context
import android.util.Log
import android.webkit.CookieManager
import android.webkit.WebStorage
import android.webkit.WebView
@@ -29,6 +28,7 @@ import androidx.core.content.edit
import androidx.webkit.ProfileStore
import androidx.webkit.WebViewCompat
import androidx.webkit.WebViewFeature
import com.vitorpamplona.quartz.utils.Log
/**
* Partitions WebView storage (cookies, localStorage, IndexedDB, service workers) per Nostr account.
@@ -24,11 +24,11 @@ import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.net.Uri
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import com.vitorpamplona.quartz.utils.Log
import com.vitorpamplona.amethyst.commons.R as CommonsR
/**