fix: BLE 로그 실시간 파일 기록 (화면 잠금/앱 종료에도 보존)
BleDebugLogger: - 매 entry마다 즉시 Downloads/VesiScan_BLE_*.log에 append - 새 BLE 연결 시 새 파일 생성 + 헤더 기록 - 기존 메모리 내 로그 + UI 표시는 동일 유지 - 화면 잠금/Doze/앱 종료에도 로그 보존 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,21 @@ class BleDebugLogger private constructor(private val context: Context) {
|
||||
private val dateFmt = SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.US)
|
||||
private val dayFmt = SimpleDateFormat("yyyy-MM-dd", Locale.US)
|
||||
|
||||
// 실시간 파일 기록 (화면 잠금/앱 종료에도 보존)
|
||||
private var liveLogFile: File? = null
|
||||
private fun ensureLiveLogFile(): File {
|
||||
if (liveLogFile == null) {
|
||||
val downloadsDir = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS)
|
||||
liveLogFile = File(downloadsDir, "VesiScan_BLE_${dateFmt.format(Date())}.log")
|
||||
}
|
||||
return liveLogFile!!
|
||||
}
|
||||
private fun appendToFile(line: String) {
|
||||
try {
|
||||
ensureLiveLogFile().appendText(line + "\n")
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
// ── Logging Methods ──
|
||||
|
||||
fun tx(command: String, dataSize: Int = 0) {
|
||||
@@ -106,6 +121,11 @@ class BleDebugLogger private constructor(private val context: Context) {
|
||||
sessionStart = System.currentTimeMillis()
|
||||
txCount = 0; rxCount = 0; errorCount = 0; packetTimeouts = 0; channelMissCount = 0
|
||||
rssiHistory.clear()
|
||||
liveLogFile = null // 새 세션 → 새 파일
|
||||
appendToFile("=== VesiScan BLE Debug Log ===")
|
||||
appendToFile("Device: $name")
|
||||
appendToFile("Session: ${dateFmt.format(Date())}")
|
||||
appendToFile("============================================================")
|
||||
add(Entry(System.currentTimeMillis(), Level.CONN, "CONNECTED $name ($address)"))
|
||||
}
|
||||
|
||||
@@ -175,6 +195,7 @@ class BleDebugLogger private constructor(private val context: Context) {
|
||||
if (entries.size > MAX_MEMORY_ENTRIES) {
|
||||
entries.removeAt(0)
|
||||
}
|
||||
appendToFile(entry.toLogLine())
|
||||
}
|
||||
|
||||
fun getEntries(): List<Entry> = entries.toList()
|
||||
|
||||
Reference in New Issue
Block a user