11package com.mg4.control.debug
22
3- import android.os.Handler
4- import android.os.Looper
53import android.util.Log
64import java.text.SimpleDateFormat
75import java.util.Date
86import java.util.Locale
9- import java.util.concurrent.CopyOnWriteArrayList
107
118/* *
129 * In-app log buffer — mirrors every Log.* call to an in-memory ring buffer
13- * so the ConsoleFragment can display them without ADB.
10+ * so the Diagnostic report can include them without ADB.
1411 *
1512 * Le buffer est un ArrayDeque sous verrou : la CopyOnWriteArrayList précédente recopiait
1613 * les 400 entrées deux fois par ligne de log, sur le thread appelant — c'est-à-dire
17- * pendant l'application d'un profil. Les listeners sont notifiés hors du chemin chaud.
14+ * pendant l'application d'un profil.
1815 */
1916object AppLogger {
2017
@@ -46,14 +43,6 @@ object AppLogger {
4643 val entries: List <Entry >
4744 get() = synchronized(lock) { buffer.toList() }
4845
49- private val listeners = CopyOnWriteArrayList < () -> Unit > ()
50-
51- private val mainHandler = Handler (Looper .getMainLooper())
52-
53- /* * Notification déjà programmée : une rafale de logs ne donne qu'un seul réveil UI. */
54- @Volatile
55- private var notifyPending = false
56-
5746 // ---- Public log methods (mirror android.util.Log) ----
5847
5948 fun d (tag : String , msg : String ) { add(tag, Level .DEBUG , msg); Log .d(tag, msg) }
@@ -66,7 +55,6 @@ object AppLogger {
6655 buffer.clear()
6756 totalCount = 0L
6857 }
69- notifyListeners()
7058 }
7159
7260 /* *
@@ -84,11 +72,6 @@ object AppLogger {
8472 }
8573 }
8674
87- // ---- Listener for live UI updates ----
88-
89- fun addListener (l : () -> Unit ) { listeners.add(l) }
90- fun removeListener (l : () -> Unit ) { listeners.remove(l) }
91-
9275 // ---- Internal ----
9376
9477 private fun add (tag : String , level : Level , msg : String ) {
@@ -99,19 +82,5 @@ object AppLogger {
9982 buffer.addLast(entry)
10083 totalCount++
10184 }
102- notifyListeners()
103- }
104-
105- /* *
106- * Réveille l'UI sur le thread principal, au plus une fois par rafale : la notification
107- * ne doit pas s'exécuter sur le thread qui journalise.
108- */
109- private fun notifyListeners () {
110- if (listeners.isEmpty() || notifyPending) return
111- notifyPending = true
112- mainHandler.post {
113- notifyPending = false
114- listeners.forEach { runCatching { it.invoke() } }
115- }
11685 }
11786}
0 commit comments