Skip to content

Commit

Permalink
Switch to the Kermit logging library (#517)
Browse files Browse the repository at this point in the history
Writing logs to file is delegated to the application layer:
- swift-log using FileLogger on iOS;
- slf4j with a rolling file policy on Android.

Note that on iOS we cannot use OSLogWriter just yet.

---------

Co-authored-by: Robbie Hanson <[email protected]>
  • Loading branch information
dpad85 and robbiehanson authored Feb 13, 2024
1 parent d0bac08 commit fd3c2a4
Show file tree
Hide file tree
Showing 220 changed files with 2,730 additions and 1,188 deletions.
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ buildscript {
classpath("org.jetbrains.kotlin:kotlin-serialization:${Versions.kotlin}")
classpath("com.squareup.sqldelight:gradle-plugin:${Versions.sqlDelight}")

// Plugins for the legacy android app
// Argument classes generation plugin for the androidx navigation component
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.AndroidLegacy.safeArgs}")
if (System.getProperty("includeAndroid")?.toBoolean() == true) {
// Plugins for the legacy android app
// Argument classes generation plugin for the androidx navigation component
classpath("androidx.navigation:navigation-safe-args-gradle-plugin:${Versions.AndroidLegacy.safeArgs}")
}
// Firebase cloud messaging plugin
classpath("com.google.gms:google-services:${Versions.fcmPlugin}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ import fr.acinq.phoenix.data.WalletPaymentId
import fr.acinq.phoenix.data.walletPaymentId
import fr.acinq.phoenix.legacy.utils.LegacyAppStatus
import fr.acinq.phoenix.legacy.utils.LegacyPrefsDatastore
import fr.acinq.phoenix.utils.extensions.id
import io.ktor.http.decodeURLPart
import io.ktor.http.encodeURLParameter
import kotlinx.coroutines.flow.filterNotNull
Expand All @@ -120,7 +119,7 @@ fun AppView(
navController: NavHostController,
) {
val log = logger("Navigation")
log.debug { "init app view composition" }
log.debug("init app view composition")

val context = LocalContext.current
val isAmountInFiat = UserPrefs.getIsAmountInFiat(context).collectAsState(false)
Expand Down Expand Up @@ -190,10 +189,10 @@ fun AppView(
onBusinessStarted = {
val next = nextScreenLink?.takeUnless { it.isBlank() }?.let { Uri.parse(it) }
if (next == null || !navController.graph.hasDeepLink(next)) {
log.debug { "redirecting from startup to home" }
log.debug("redirecting from startup to home")
popToHome(navController)
} else {
log.debug { "redirecting from startup to $next" }
log.debug("redirecting from startup to $next")
navController.navigate(next, navOptions = navOptions {
popUpTo(navController.graph.id) { inclusive = true }
})
Expand Down Expand Up @@ -291,7 +290,7 @@ fun AppView(
val paymentId = if (id != null && direction != null) WalletPaymentId.create(direction, id) else null
if (paymentId != null) {
RequireStarted(walletState, nextUri = "phoenix:payments/${direction}/${id}") {
log.debug { "navigating to payment-details id=$id" }
log.debug("navigating to payment-details id=$id")
PaymentDetailsView(
paymentId = paymentId,
onBackClick = {
Expand Down Expand Up @@ -450,7 +449,7 @@ fun AppView(
val isDataMigrationExpected by LegacyPrefsDatastore.getDataMigrationExpected(context).collectAsState(initial = null)
val lastCompletedPayment by business.paymentsManager.lastCompletedPayment.collectAsState()
lastCompletedPayment?.let {
log.debug { "completed payment=${lastCompletedPayment?.id()} with data-migration=$isDataMigrationExpected" }
// log.debug { "completed payment=${lastCompletedPayment?.id()} with data-migration=$isDataMigrationExpected" }
LaunchedEffect(key1 = it.walletPaymentId()) {
if (isDataMigrationExpected == false) {
navigateToPaymentDetails(navController, id = it.walletPaymentId(), isFromEvent = true)
Expand Down Expand Up @@ -545,7 +544,6 @@ private fun RequireStarted(
nextUri: String? = null,
children: @Composable () -> Unit
) {
val log = logger("Navigation")
if (serviceState == null) {
// do nothing
} else if (serviceState !is NodeServiceState.Running) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ package fr.acinq.phoenix.android

import androidx.navigation.NavController
import androidx.navigation.NavOptionsBuilder
import org.kodein.log.LoggerFactory
import org.kodein.log.newLogger
import org.slf4j.LoggerFactory


sealed class Screen(val route: String) {
Expand Down Expand Up @@ -68,17 +67,17 @@ sealed class Screen(val route: String) {
}

fun NavController.navigate(screen: Screen, arg: List<Any> = emptyList(), builder: NavOptionsBuilder.() -> Unit = {}) {
val log = newLogger(LoggerFactory.default)
val log = LoggerFactory.getLogger("NavController")
val path = arg.joinToString{ "/$it" }
val route = "${screen.route}$path"
log.debug { "navigating from ${currentDestination?.route} to $route" }
log.debug("navigating from ${currentDestination?.route} to $route")
try {
if (route == currentDestination?.route) {
log.warning { "cannot navigate to same route" }
log.warn("cannot navigate to same route")
} else {
navigate(route, builder)
}
} catch (e: Exception) {
log.error(e) { "failed to navigate to $route" }
log.error("failed to navigate to $route: " , e)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import fr.acinq.phoenix.android.utils.Converter.toMilliSatoshi
import fr.acinq.phoenix.android.utils.Converter.toPlainString
import fr.acinq.phoenix.android.utils.Converter.toPrettyString
import fr.acinq.phoenix.android.utils.Converter.toUnit
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.android.utils.negativeColor
import fr.acinq.phoenix.android.utils.outlinedTextFieldColors
import fr.acinq.phoenix.data.BitcoinUnit
Expand Down Expand Up @@ -390,7 +389,6 @@ fun AmountHeroInput(
inputTextSize: TextUnit = 16.sp,
enabled: Boolean = true,
) {
val log = logger("AmountHeroInput")
val context = LocalContext.current
val prefBitcoinUnit = LocalBitcoinUnit.current
val prefFiat = LocalFiatCurrency.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.datastore.HomeAmountDisplayMode
import fr.acinq.phoenix.android.utils.datastore.UserPrefs
import fr.acinq.phoenix.android.utils.findActivity
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.data.WalletPaymentId
import fr.acinq.phoenix.legacy.utils.LegacyPrefsDatastore
import kotlinx.coroutines.flow.combine
Expand All @@ -79,7 +78,6 @@ fun HomeView(
onShowNotifications: () -> Unit,
onRequestLiquidityClick: () -> Unit,
) {
val log = logger("HomeView")
val context = LocalContext.current
val torEnabledState = UserPrefs.getIsTorEnabled(context).collectAsState(initial = null)
val connections by business.connectionsManager.connections.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fun CreateWalletView(
is Initialization.Model.Ready -> {
val entropy = remember { Lightning.randomBytes(16) }
LaunchedEffect(key1 = entropy) {
log.debug { "generating new wallet..." }
log.debug("generating new wallet...")
postIntent(Initialization.Intent.GenerateWallet(entropy))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ sealed class RestoreWalletViewState {
fun RestoreWalletView(
onSeedWritten: () -> Unit
) {
val log = logger("RestoreWalletView")
val nc = navController
val context = LocalContext.current
val vm: InitViewModel = viewModel(factory = InitViewModel.Factory(controllerFactory, CF::initialization))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import androidx.compose.ui.unit.sp
import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.components.*
import fr.acinq.phoenix.android.utils.datastore.UserPrefs
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.controllers.payments.Scan
import fr.acinq.phoenix.data.lnurl.LnurlAuth

Expand All @@ -43,8 +42,6 @@ fun LnurlAuthView(
onLoginClick: (Scan.Intent.LnurlAuthFlow) -> Unit,
onAuthSchemeInfoClick: () -> Unit
) {
val log = logger("LnurlAuthView")

val context = LocalContext.current
var showHowItWorks by remember { mutableStateOf(false) }
val prefAuthScheme by UserPrefs.getLnurlAuthScheme(context).collectAsState(initial = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import fr.acinq.phoenix.android.preferredAmountUnit
import fr.acinq.phoenix.android.utils.BitmapHelper
import fr.acinq.phoenix.android.utils.Converter.toPrettyStringWithFallback
import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.android.utils.safeLet
import fr.acinq.phoenix.controllers.payments.Scan
import fr.acinq.phoenix.data.lnurl.LnurlError
Expand All @@ -58,9 +57,6 @@ fun LnurlPayView(
onBackClick: () -> Unit,
onSendLnurlPayClick: (Scan.Intent.LnurlPayFlow) -> Unit
) {
val log = logger("LnurlPayView")
log.debug { "init lnurl-pay view with url=${model.paymentIntent}" }

val context = LocalContext.current
val balance = business.balanceManager.balance.collectAsState(null).value
val prefUnit = preferredAmountUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import fr.acinq.phoenix.android.fiatRate
import fr.acinq.phoenix.android.preferredAmountUnit
import fr.acinq.phoenix.android.utils.Converter.toPrettyStringWithFallback
import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.controllers.payments.Scan
import fr.acinq.phoenix.data.lnurl.LnurlError

Expand All @@ -46,9 +45,6 @@ fun LnurlWithdrawView(
onBackClick: () -> Unit,
onWithdrawClick: (Scan.Intent.LnurlWithdrawFlow) -> Unit
) {
val log = logger("LnurlWithdrawView")
log.debug { "init lnurl-withdraw view with url=${model.lnurlWithdraw}" }

val context = LocalContext.current
val prefUnit = preferredAmountUnit
val rate = fiatRate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ fun ScanDataView(
onBackClick: () -> Unit,
onAuthSchemeInfoClick: () -> Unit,
) {
val log = logger("ScanDataView")
var initialInput = remember { input }
val peer by business.peerManager.peerState.collectAsState()
val trampolineFees = peer?.walletParams?.trampolineFees?.firstOrNull()
Expand Down Expand Up @@ -174,7 +173,6 @@ fun ReadDataView(
onBackClick: () -> Unit,
onScannedText: (String) -> Unit,
) {
val log = logger("ReadDataView")
val context = LocalContext.current.applicationContext

var showManualInputDialog by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -248,7 +246,6 @@ fun BoxScope.ScannerView(
onScanViewBinding: (DecoratedBarcodeView) -> Unit,
onScannedText: (String) -> Unit
) {
val log = logger("ScannerView")
// scanner view using a legacy binding
AndroidViewBinding(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -264,7 +261,6 @@ fun BoxScope.ScannerView(
override fun barcodeResult(result: BarcodeResult?) {
result?.text?.trim()?.takeIf { it.isNotBlank() }?.let {
scanView.pause()
log.debug { "scanned text=$it" }
onScannedText(it)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.business
import fr.acinq.phoenix.android.components.*
import fr.acinq.phoenix.android.utils.Converter.toPrettyString
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.android.utils.safeLet
import fr.acinq.phoenix.controllers.payments.Scan
import fr.acinq.phoenix.utils.extensions.isAmountlessTrampoline
Expand All @@ -49,9 +48,6 @@ fun SendLightningPaymentView(
onBackClick: () -> Unit,
onPayClick: (Scan.Intent.InvoiceFlow.SendInvoicePayment) -> Unit
) {
val log = logger("SendLightningPaymentView")
log.debug { "init sendview amount=${paymentRequest.amount} desc=${paymentRequest.description}" }

val context = LocalContext.current
val balance = business.balanceManager.balance.collectAsState(null).value
val prefBitcoinUnit = LocalBitcoinUnit.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import fr.acinq.phoenix.android.components.feedback.ErrorMessage
import fr.acinq.phoenix.android.payments.spliceout.spliceFailureDetails
import fr.acinq.phoenix.android.utils.Converter.toPrettyString
import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.android.utils.positiveColor
import fr.acinq.phoenix.data.BitcoinUnit

Expand All @@ -63,8 +62,6 @@ fun CpfpView(
channelId: ByteVector32,
onSuccess: () -> Unit,
) {
val logger = logger("CpfpView")

val peerManager = business.peerManager
val vm = viewModel<CpfpViewModel>(factory = CpfpViewModel.Factory(peerManager))
val mempoolFeerate by business.appConfigurationManager.mempoolFeerate.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ private fun ConfirmationView(
onCpfpSuccess: () -> Unit,
minDepth: Int? = null, // sometimes we know how many confirmations are needed
) {
val log = logger("PaymentDetailsSplashView")
val txUrl = txUrl(txId = txId)
val context = LocalContext.current
val electrumClient = business.electrumClient
Expand All @@ -670,9 +669,9 @@ private fun ConfirmationView(

suspend fun getConfirmations(): Int {
val confirmations = electrumClient.getConfirmations(txId)
log.debug { "retrieved confirmations=$confirmations from electrum for tx=$txId" }
// log.debug { "retrieved confirmations=$confirmations from electrum for tx=$txId" }
return confirmations ?: run {
log.debug { "retrying getConfirmations from electrum in 5 sec" }
// log.debug { "retrying getConfirmations from electrum in 5 sec" }
delay(5_000)
getConfirmations()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import fr.acinq.phoenix.android.components.*
import fr.acinq.phoenix.android.components.feedback.ErrorMessage
import fr.acinq.phoenix.android.utils.Converter.toBasicAbsoluteDateString
import fr.acinq.phoenix.android.utils.copyToClipboard
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.android.utils.positiveColor
import fr.acinq.phoenix.android.utils.shareFile

Expand All @@ -42,7 +41,6 @@ import fr.acinq.phoenix.android.utils.shareFile
fun CsvExportView(
onBackClick: () -> Unit,
) {
val log = logger("CsvExportView")
val context = LocalContext.current
val vm: CsvExportViewModel = viewModel(
factory = CsvExportViewModel.Factory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import fr.acinq.phoenix.android.components.DefaultScreenLayout
import fr.acinq.phoenix.android.components.ItemCard
import fr.acinq.phoenix.android.payments.details.PaymentLine
import fr.acinq.phoenix.android.payments.details.PaymentLineLoading
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.data.WalletPaymentId
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
Expand Down Expand Up @@ -103,7 +102,6 @@ fun PaymentsHistoryView(
onPaymentClick: (WalletPaymentId) -> Unit,
onCsvExportClick: () -> Unit,
) {
val log = logger("PaymentsHistory")
val listState = rememberLazyListState()
val allPaymentsCount by business.paymentsManager.paymentsCount.collectAsState()
val payments by paymentsViewModel.paymentsFlow.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import fr.acinq.phoenix.android.components.*
import fr.acinq.phoenix.android.components.feedback.ErrorMessage
import fr.acinq.phoenix.android.utils.Converter.toPrettyString
import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.logger
import fr.acinq.phoenix.data.BitcoinUnit
import fr.acinq.phoenix.data.MempoolFeerate

Expand All @@ -57,9 +56,6 @@ fun SendSpliceOutView(
onBackClick: () -> Unit,
onSpliceOutSuccess: () -> Unit,
) {
val log = logger("SendSpliceOut")
log.debug { "init splice-out with amount=$requestedAmount address=$address" }

val context = LocalContext.current
val prefBtcUnit = LocalBitcoinUnit.current
val keyboardManager = LocalSoftwareKeyboardController.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package fr.acinq.phoenix.android.security

import android.content.Context
import org.kodein.log.LoggerFactory
import org.kodein.log.newLogger
import org.slf4j.LoggerFactory
import java.io.File

sealed class SeedFileState {
Expand All @@ -36,7 +35,7 @@ sealed class SeedFileState {
object SeedManager {
private val BASE_DATADIR = "node-data"
private const val SEED_FILE = "seed.dat"
private val log = newLogger(LoggerFactory.default)
private val log = LoggerFactory.getLogger(this::class.java) // newLogger(LoggerFactory.default)

fun getDatadir(context: Context): File {
return File(context.filesDir, BASE_DATADIR)
Expand All @@ -52,7 +51,7 @@ object SeedManager {
else -> SeedFileState.Error.UnhandledSeedType
}
} catch (e: Exception) {
log.error(e) { "failed to read seed: " }
log.error("failed to read seed: ", e)
SeedFileState.Error.Unreadable(e.localizedMessage)
}

Expand Down Expand Up @@ -91,7 +90,7 @@ object SeedManager {
// 3 - decrypt temp file and check validity; if correct, move temp file to final file
val checkSeed = loadSeedFromDir(dir, temp.name) as EncryptedSeed.V2
if (!checkSeed.ciphertext.contentEquals(seed.ciphertext)) {
log.warning { "seed check do not match!" }
log.warn("seed check do not match!")
// throw WriteErrorCheckDontMatch
}
temp.copyTo(File(dir, SEED_FILE), overwrite)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ import fr.acinq.phoenix.android.R
import fr.acinq.phoenix.android.components.*
import fr.acinq.phoenix.android.navController
import fr.acinq.phoenix.android.utils.annotatedStringResource
import fr.acinq.phoenix.android.utils.logger


@Composable
fun AboutView() {
val log = logger("AboutView")
val nc = navController
val context = LocalContext.current

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import kotlinx.coroutines.launch
fun AppLockView(
onBackClick: () -> Unit,
) {
val log = logger("AppLockView")
val context = LocalContext.current
val authStatus = BiometricsHelper.authStatus(context)
val isScreenLockActive by UserPrefs.getIsScreenLockActive(context).collectAsState(null)
Expand Down
Loading

0 comments on commit fd3c2a4

Please sign in to comment.