apple_kit

Apple-native services for Radroots iOS and macOS apps
git clone https://radroots.dev/git/apple_kit.git
Log | Files | Refs | README

RadrootsTelemetryTesting.swift (1034B)


      1 import Foundation
      2 import RadrootsKit
      3 
      4 public actor RadrootsRecordingTelemetry: RadrootsTelemetry {
      5     private let minimumLevel: RadrootsTelemetryLevel
      6     private var recordedEventsValue: [RadrootsTelemetryEvent]
      7 
      8     public init(minimumLevel: RadrootsTelemetryLevel = .trace) {
      9         self.minimumLevel = minimumLevel
     10         self.recordedEventsValue = []
     11     }
     12 
     13     public func record(_ event: RadrootsTelemetryEvent) async {
     14         guard event.level >= minimumLevel else {
     15             return
     16         }
     17         recordedEventsValue.append(event)
     18     }
     19 
     20     public func reset() {
     21         recordedEventsValue.removeAll()
     22     }
     23 
     24     public var recordedEvents: [RadrootsTelemetryEvent] {
     25         recordedEventsValue
     26     }
     27 
     28     public var recordedEventCount: Int {
     29         recordedEventsValue.count
     30     }
     31 
     32     public var recordedEventNames: [String] {
     33         recordedEventsValue.map(\.name)
     34     }
     35 
     36     public func events(named name: String) -> [RadrootsTelemetryEvent] {
     37         recordedEventsValue.filter { $0.name == name }
     38     }
     39 }