瀏覽代碼

Switching from print/NSLog to log

Jonas Björkert 1 年之前
父節點
當前提交
0dc2919cc6

+ 3 - 3
LoopFollow/BackgroundRefresh/BT/BLEManager.swift

@@ -124,9 +124,9 @@ extension BLEManager: CBCentralManagerDelegate {
     func centralManagerDidUpdateState(_ central: CBCentralManager) {
         switch central.state {
         case .poweredOn:
-            print("[BLE] Central poweredOn.")
+            LogManager.shared.log(category: .bluetooth, message: "Central poweredOn", isDebug: true)
         default:
-            print("[BLE] Central state = \(central.state.rawValue), not powered on.")
+            LogManager.shared.log(category: .bluetooth, message: "Central state = \(central.state.rawValue), not powered on.", isDebug: true)
         }
     }
 
@@ -157,7 +157,7 @@ extension BLEManager: CBCentralManagerDelegate {
 
             devices = devices
         } else {
-            print("Device not found in devices array for update")
+            LogManager.shared.log(category: .bluetooth, message: "Device not found in devices array for update")
         }
     }
 }

+ 3 - 3
LoopFollow/BackgroundRefresh/BT/BluetoothDevice.swift

@@ -82,7 +82,7 @@ class BluetoothDevice: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
     }
 
     func startScanning() -> BluetoothDevice.startScanningResult {
-        print("[BLE] startScanning")
+        LogManager.shared.log(category: .bluetooth, message: "Start Scanning", isDebug: true)
 
         var returnValue = BluetoothDevice.startScanningResult.unknown
 
@@ -139,7 +139,7 @@ class BluetoothDevice: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
     }
 
     fileprivate func stopScanAndconnect(to peripheral: CBPeripheral) {
-        print("[BLE] stopScanAndconnect")
+        LogManager.shared.log(category: .bluetooth, message: "Stop Scan And Connect", isDebug: true)
 
         self.centralManager?.stopScan()
         self.deviceAddress = peripheral.identifier.uuidString
@@ -218,7 +218,7 @@ class BluetoothDevice: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
     }
 
     func centralManagerDidUpdateState(_ central: CBCentralManager) {
-        print("[BLE] centralManagerDidUpdateState")
+        LogManager.shared.log(category: .bluetooth, message: "Central Manager Did Update State", isDebug: true)
 
         timeStampLastStatusUpdate = Date()
 

+ 6 - 6
LoopFollow/Controllers/AlarmSound.swift

@@ -252,7 +252,7 @@ class AlarmSound {
             try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .mixWithOthers)
             try AVAudioSession.sharedInstance().setActive(true)
         } catch {
-            print(error)
+            LogManager.shared.log(category: .general, message: "Enable audio error: \(error)")
         }
     }
 }
@@ -261,15 +261,15 @@ class AudioPlayerDelegate: NSObject, AVAudioPlayerDelegate {
 
     /* audioPlayerDidFinishPlaying:successfully: is called when a sound has finished playing. This method is NOT called if the player is stopped due to an interruption. */
     func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
-        NSLog("AlarmRule - audioPlayerDidFinishPlaying (\(flag))")
+        LogManager.shared.log(category: .general, message: "AlarmRule - audioPlayerDidFinishPlaying (\(flag))", isDebug: true)
     }
     
     /* if an error occurs while decoding it will be reported to the delegate. */
     func audioPlayerDecodeErrorDidOccur(_ player: AVAudioPlayer, error: Error?) {
         if let error = error {
-            NSLog("AlarmRule - audioPlayerDecodeErrorDidOccur: \(error)")
+            LogManager.shared.log(category: .general, message: "AlarmRule - audioPlayerDecodeErrorDidOccur: \(error)")
         } else {
-            NSLog("AlarmRule - audioPlayerDecodeErrorDidOccur")
+            LogManager.shared.log(category: .general, message: "AlarmRule - audioPlayerDecodeErrorDidOccur")
         }
     }
     
@@ -277,14 +277,14 @@ class AudioPlayerDelegate: NSObject, AVAudioPlayerDelegate {
     
     /* audioPlayerBeginInterruption: is called when the audio session has been interrupted while the player was playing. The player will have been paused. */
     func audioPlayerBeginInterruption(_ player: AVAudioPlayer) {
-        NSLog("AlarmRule - audioPlayerBeginInterruption")
+        LogManager.shared.log(category: .general, message: "AlarmRule - audioPlayerBeginInterruption")
     }
     
     
     /* audioPlayerEndInterruption:withOptions: is called when the audio session interruption has ended and this player had been interrupted while playing. */
     /* Currently the only flag is AVAudioSessionInterruptionFlags_ShouldResume. */
     func audioPlayerEndInterruption(_ player: AVAudioPlayer, withOptions flags: Int) {
-        NSLog("AlarmRule - audioPlayerEndInterruption withOptions: \(flags)")
+        LogManager.shared.log(category: .general, message: "AlarmRule - audioPlayerEndInterruption withOptions: \(flags)")
     }
 }
 

+ 8 - 7
LoopFollow/Controllers/Alarms.swift

@@ -960,7 +960,8 @@ extension MainViewController {
         // Speak always
         if always {
             speakBG(currentValue: currentValue, previousValue: previousValue)
-            print("Speaking because 'Always' is enabled.")
+            LogManager.shared.log(category: .general, message: "Speaking because 'Always' is enabled.", isDebug: true)
+
             return
         }
         
@@ -968,7 +969,7 @@ extension MainViewController {
         if speakLowBG {
             if currentValue <= Int(lowThreshold) || previousValue <= Int(lowThreshold) {
                 speakBG(currentValue: currentValue, previousValue: previousValue)
-                print("Speaking because of 'Low' condition.")
+                LogManager.shared.log(category: .general, message: "Speaking because of 'Low' condition.", isDebug: true)
                 return
             }
         }
@@ -984,7 +985,7 @@ extension MainViewController {
                 currentValue <= Int(lowThreshold) || previousValue <= Int(lowThreshold) ||
                 ((currentValue <= Int(highThreshold) && (previousValue - currentValue) >= Int(fastDropDelta))) {
                 speakBG(currentValue: currentValue, previousValue: previousValue)
-                print("Speaking because of 'Proactive Low' condition. Predictive trigger: \(predictiveTrigger)")
+                LogManager.shared.log(category: .general, message: "Speaking because of 'Proactive Low' condition. Predictive trigger: \(predictiveTrigger)", isDebug: true)
                 return
             }
         }
@@ -993,12 +994,12 @@ extension MainViewController {
         if speakHighBG {
             if currentValue >= Int(highThreshold) || previousValue >= Int(highThreshold) {
                 speakBG(currentValue: currentValue, previousValue: previousValue)
-                print("Speaking because of 'High' condition.")
+                LogManager.shared.log(category: .general, message: "Speaking because of 'High' condition.", isDebug: true)
                 return
             }
         }
-        
-        print("No condition met for speaking.")
+
+        LogManager.shared.log(category: .general, message: "No condition met for speaking.", isDebug: true)
     }
     
     struct AnnouncementTexts {
@@ -1074,7 +1075,7 @@ extension MainViewController {
         // If `lastSpeechTime` is `nil` (i.e., this is the first time `speakBG` is being called), use `Date.distantPast` as the default
         // value to ensure that the `guard` statement passes and the announcement is made.
         guard currentTime.timeIntervalSince(lastSpeechTime ?? .distantPast) >= 30 else {
-            print("Repeated calls to speakBG detected!")
+            LogManager.shared.log(category: .general, message: "Repeated calls to speakBG detected!", isDebug: true)
             return
         }
 

+ 1 - 1
LoopFollow/Controllers/Graphs.swift

@@ -1714,7 +1714,7 @@ extension MainViewController {
               index.rawValue < chart.dataSets.count,
               let smallChartData = BGChartFull.lineData,
               index.rawValue < smallChartData.dataSets.count else {
-            print("Warning: Invalid GraphDataIndex \(index.description) or lineData is nil.")
+            //print("Warning: Invalid GraphDataIndex \(index.description) or lineData is nil.")
             return (nil, nil)
         }
 

+ 6 - 6
LoopFollow/Remote/PushNotificationManager.swift

@@ -207,7 +207,7 @@ class PushNotificationManager {
 
         if !missingFields.isEmpty {
             let errorMessage = "Missing required fields, check your remote settings: \(missingFields.joined(separator: ", "))"
-            print(errorMessage)
+            LogManager.shared.log(category: .apns, message: errorMessage)
             completion(false, errorMessage)
             return
         }
@@ -218,28 +218,28 @@ class PushNotificationManager {
 
         if !missingFields.isEmpty {
             let errorMessage = "Missing required data, verify that you are using the latest version of Trio: \(missingFields.joined(separator: ", "))"
-            print(errorMessage)
+            LogManager.shared.log(category: .apns, message: errorMessage)
             completion(false, errorMessage)
             return
         }
 
         if let validationErrors = validateCredentials() {
             let errorMessage = "Credential validation failed: \(validationErrors.joined(separator: ", "))"
-            print(errorMessage)
+            LogManager.shared.log(category: .apns, message: errorMessage)
             completion(false, errorMessage)
             return
         }
 
         guard let url = constructAPNsURL() else {
             let errorMessage = "Failed to construct APNs URL"
-            print(errorMessage)
+            LogManager.shared.log(category: .apns, message: errorMessage)
             completion(false, errorMessage)
             return
         }
 
         guard let jwt = getOrGenerateJWT() else {
             let errorMessage = "Failed to generate JWT, please check that the token is correct."
-            print(errorMessage)
+            LogManager.shared.log(category: .apns, message: errorMessage)
             completion(false, errorMessage)
             return
         }
@@ -260,7 +260,7 @@ class PushNotificationManager {
             let task = URLSession.shared.dataTask(with: request) { data, response, error in
                 if let error = error {
                     let errorMessage = "Failed to send push notification: \(error.localizedDescription)"
-                    print(errorMessage)
+                    LogManager.shared.log(category: .apns, message: errorMessage)
                     completion(false, errorMessage)
                     return
                 }

+ 1 - 1
LoopFollow/ViewControllers/SnoozeViewController.swift

@@ -246,7 +246,7 @@ class SnoozeViewController: UIViewController, UNUserNotificationCenterDelegate {
             alarms.reloadSnoozeTime(key: "alertTempTargetEndSnoozedTime", setNil: false, value: currentDate.addingTimeInterval(snoozeDuration))
 
         default:
-            print("Unhandled alarm: \(AlarmSound.whichAlarm)")
+            LogManager.shared.log(category: .alarm, message: "Unhandled alarm: \(AlarmSound.whichAlarm)")
         }
     }