Skip to content

Commit 2970c69

Browse files
committed
chore: review
1 parent 19bfaac commit 2970c69

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

app/src/main/java/to/bitkit/services/LightningService.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class LightningService @Inject constructor(
339339
val node = this.node ?: throw ServiceError.NodeNotSetup
340340

341341
return ServiceQueue.LDK.background {
342-
runCatching {
342+
try {
343343
val pushToCounterpartyMsat = pushToCounterpartySats?.let { it * 1000u }
344344
Logger.debug("Initiating channel open (sats: $channelAmountSats) with peer: ${peer.uri}")
345345

@@ -361,11 +361,11 @@ class LightningService @Inject constructor(
361361

362362
Logger.info("Channel open initiated, result: $result")
363363

364-
result
365-
}.onFailure { e ->
366-
val error = if (e is NodeException) LdkError(e) else e
364+
Result.success(result)
365+
} catch (e: NodeException) {
366+
val error = LdkError(e)
367367
Logger.error("Error initiating channel open", error)
368-
error
368+
Result.failure(error)
369369
}
370370
}
371371
}

app/src/main/java/to/bitkit/ui/screens/wallets/activity/components/ActivityListSimple.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.Column
44
import androidx.compose.foundation.layout.fillMaxWidth
55
import androidx.compose.foundation.layout.padding
66
import androidx.compose.foundation.layout.wrapContentWidth
7-
import androidx.compose.material3.HorizontalDivider
87
import androidx.compose.runtime.Composable
98
import androidx.compose.ui.Alignment
109
import androidx.compose.ui.Modifier

app/src/main/java/to/bitkit/utils/Logger.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ private fun buildSessionLogFilePath(source: LogSource): String {
248248
return sessionLogFilePath
249249
}
250250

251-
private fun formatLog(level: LogLevel, msg: String?, tag: String, path: String, line: Int): String {
251+
private fun formatLog(level: LogLevel, msg: String?, context: String, path: String, line: Int): String {
252252
val timestamp = utcDateFormatterOf(DatePattern.LOG_LINE).format(Date())
253253
val message = msg?.trim().orEmpty()
254-
val context = if (tag.isNotEmpty()) " - $tag" else ""
254+
val contextString = if (context.isNotEmpty()) " - $context" else ""
255255
return String.format(
256256
Locale.US,
257257
"%s %-7s [%s:%d] %s%s",
@@ -260,10 +260,24 @@ private fun formatLog(level: LogLevel, msg: String?, tag: String, path: String,
260260
path,
261261
line,
262262
message,
263-
context,
263+
contextString,
264264
)
265265
}
266266

267+
/**
268+
* Determines which stack frame to use for caller info.
269+
*
270+
* The value 5 is chosen based on the current call chain:
271+
* - [0] `Thread.getStackTrace`
272+
* - [1] `getCallerPath`/`getCallerLine`
273+
* - [2] `LoggerImpl.log_method` (e.g., debug, info, etc.)
274+
* - [3] `LdkLogWriter.log_method`
275+
* - [4] external caller
276+
* - [5] actual caller of logging function
277+
*
278+
* If the call chain changes, this index may need to be updated.
279+
*/
280+
267281
private const val STACK_INDEX = 5
268282
private fun getCallerPath(): String = Thread.currentThread().stackTrace.getOrNull(STACK_INDEX)?.fileName ?: "Unknown"
269283
private fun getCallerLine(): Int = Thread.currentThread().stackTrace.getOrNull(STACK_INDEX)?.lineNumber ?: -1

0 commit comments

Comments
 (0)