diff --git a/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt b/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt index d081f16..1090778 100644 --- a/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt +++ b/app/src/main/java/com/example/medilightv2android/services/BleDebugLogger.kt @@ -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 = entries.toList()