Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/claude-code-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ jobs:
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
# use_sticky_comment: "true" # doesn't work
# use_sticky_comment: "true" # doesn't work
plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
plugins: 'code-review@claude-code-plugins'
prompt: '/code-review:code-review ${{ github.repository }}/pull/${{ github.event.pull_request.number }}'
# Allow Claude bot to trigger this workflow
allowed_bots: 'claude[bot]'
# Allow Claude to use GH CLI for reading external PR details and fetch web content
claude_args: '--allowed-tools Bash(gh:*) WebFetch'
31 changes: 19 additions & 12 deletions app/src/main/java/to/bitkit/utils/Logger.kt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could make LoggerImpl

Copy link
Member

@jvsena42 jvsena42 Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Ldk LogSource is not used anymore, could be removed

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ enum class LogLevel { PERF, VERBOSE, GOSSIP, TRACE, DEBUG, INFO, WARN, ERROR; }

val Logger = AppLogger()

class AppLogger(private val source: LogSource = LogSource.Bitkit) {
class AppLogger {
companion object {
private const val TAG = "Logger"
private var saver: LogSaver? = null

fun getOrCreateSaver(): LogSaver {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this method is called by two classes on init(). could have a race condittion

Copy link
Member

@jvsena42 jvsena42 Jan 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but as far as I can see, it would just replace the instance. WDYT?

if (saver == null) {
val sessionPath = runCatching { buildSessionLogFilePath() }.getOrElse { "" }
saver = LogSaverImpl(sessionPath)
}
return requireNotNull(saver) { "saver should be initialized" }
}
}

private var delegate: LoggerImpl? = null
Expand All @@ -46,13 +55,13 @@ class AppLogger(private val source: LogSource = LogSource.Bitkit) {
}

private fun createDelegate(): LoggerImpl {
val sessionPath = runCatching { buildSessionLogFilePath(source) }.getOrElse { "" }
return LoggerImpl(APP, LogSaverImpl(source, sessionPath))
return LoggerImpl(APP, getOrCreateSaver())
}

fun reset() {
warn("Wiping entire logs directory…", context = TAG)
runCatching { Env.logDir.deleteRecursively() }
saver = null
delegate = runCatching { createDelegate() }.getOrNull()
}
Comment on lines 61 to 66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on app wipe, reset() could race with getOrCreateSaver()


Expand Down Expand Up @@ -114,7 +123,7 @@ class AppLogger(private val source: LogSource = LogSource.Bitkit) {
}
}

class LoggerImpl(
private class LoggerImpl(
private val tag: String = APP,
private val saver: LogSaver,
private val compact: Boolean = COMPACT,
Expand Down Expand Up @@ -198,7 +207,6 @@ interface LogSaver {
}

class LogSaverImpl(
source: LogSource,
private val sessionFilePath: String,
) : LogSaver {
private val queue: CoroutineScope by lazy {
Expand All @@ -207,7 +215,7 @@ class LogSaverImpl(

init {
if (sessionFilePath.isNotEmpty()) {
log("Log session for '${source.name}' initialized with file path: '$sessionFilePath'")
log("Log session initialized with file path: '$sessionFilePath'")

// Clean all old log files in background
CoroutineScope(Dispatchers.IO).launch {
Expand All @@ -221,8 +229,9 @@ class LogSaverImpl(

queue.launch {
runCatching {
val sanitized = message.replace("\n", " ")
FileOutputStream(File(sessionFilePath), true).use { stream ->
stream.write("$message\n".toByteArray())
stream.write("$sanitized\n".toByteArray())
}
}.onFailure {
Log.e(APP, "Error writing to log file: '$sessionFilePath'", it)
Expand Down Expand Up @@ -273,8 +282,7 @@ class LogSaverImpl(

class LdkLogWriter(
private val maxLogLevel: LdkLogLevel = Env.ldkLogLevel,
private val source: LogSource = LogSource.Ldk,
saver: LogSaver = LogSaverImpl(source, buildSessionLogFilePath(source)),
saver: LogSaver = AppLogger.getOrCreateSaver(),
) : LogWriter {
private val delegate: LoggerImpl = LoggerImpl(LDK, saver)

Expand All @@ -296,11 +304,10 @@ class LdkLogWriter(
}
}

private fun buildSessionLogFilePath(source: LogSource): String {
private fun buildSessionLogFilePath(): String {
val logDir = Env.logDir
val sourceName = source.name.lowercase()
val timestamp = utcDateFormatterOf(DatePattern.LOG_FILE).format(Date())
val path = logDir.resolve("${sourceName}_$timestamp.log").path
val path = logDir.resolve("bitkit_$timestamp.log").path
return path
}

Expand Down
Loading