@@ -12,6 +12,7 @@ extension CbfClient {
12
12
// Track monitoring tasks per client for clean cancellation
13
13
private static var monitoringTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
14
14
private static var warningTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
15
+ private static var logTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
15
16
private static var heartbeatTasks : [ ObjectIdentifier : Task < Void , Never > ] = [ : ]
16
17
private static var lastInfoAt : [ ObjectIdentifier : Date ] = [ : ]
17
18
private static let monitoringTasksQueue = DispatchQueue ( label: " cbf.monitoring.tasks " )
@@ -179,6 +180,30 @@ extension CbfClient {
179
180
Self . monitoringTasksQueue. sync {
180
181
Self . warningTasks [ id] = warnings
181
182
}
183
+
184
+ // Log listener for detailed debugging
185
+ let logs = Task { [ self ] in
186
+ while true {
187
+ if Task . isCancelled { break }
188
+ do {
189
+ #if DEBUG
190
+ print ( " [Kyoto] calling nextLog() " )
191
+ #endif
192
+ let log = try await self . nextLog ( )
193
+ #if DEBUG
194
+ print ( " [Kyoto] nextLog() returned: \( log) " )
195
+ #endif
196
+ } catch is CancellationError {
197
+ break
198
+ } catch {
199
+ // ignore
200
+ }
201
+ }
202
+ }
203
+
204
+ Self . monitoringTasksQueue. sync {
205
+ Self . logTasks [ id] = logs
206
+ }
182
207
}
183
208
184
209
func stopBackgroundMonitoring( ) {
@@ -188,6 +213,7 @@ extension CbfClient {
188
213
task. cancel ( )
189
214
if let hb = Self . heartbeatTasks. removeValue ( forKey: id) { hb. cancel ( ) }
190
215
if let wt = Self . warningTasks. removeValue ( forKey: id) { wt. cancel ( ) }
216
+ if let lt = Self . logTasks. removeValue ( forKey: id) { lt. cancel ( ) }
191
217
Self . lastInfoAt. removeValue ( forKey: id)
192
218
}
193
219
}
@@ -196,9 +222,11 @@ extension CbfClient {
196
222
Self . monitoringTasksQueue. sync {
197
223
for (_, task) in Self . monitoringTasks { task. cancel ( ) }
198
224
for (_, wt) in Self . warningTasks { wt. cancel ( ) }
225
+ for (_, lt) in Self . logTasks { lt. cancel ( ) }
199
226
for (_, hb) in Self . heartbeatTasks { hb. cancel ( ) }
200
227
Self . monitoringTasks. removeAll ( )
201
228
Self . warningTasks. removeAll ( )
229
+ Self . logTasks. removeAll ( )
202
230
Self . heartbeatTasks. removeAll ( )
203
231
Self . lastInfoAt. removeAll ( )
204
232
}
0 commit comments