88
99import Foundation
1010import CloudKit
11- import os. log
11+ import OSLog
12+
13+ // TODO: Where to?
14+ let ckLog = makeLogger ( subsystem: " WWDC " , category: " CloudKit " )
1215
1316extension Error {
1417
@@ -20,51 +23,39 @@ extension Error {
2023
2124 func resolveConflict( with resolver: ( CKRecord , CKRecord ) -> CKRecord ? ) -> CKRecord ? {
2225 guard let effectiveError = self as? CKError else {
23- os_log ( " resolveConflict called on an error that was not a CKError. The error was %{public}@ " ,
24- log: . default,
25- type: . fault,
26- String ( describing: self ) )
26+ ckLog. fault ( " resolveConflict called on an error that was not a CKError. The error was \( String ( describing: self ) , privacy: . public) " )
2727 return nil
2828 }
2929
3030 guard effectiveError. code == . serverRecordChanged else {
31- os_log ( " resolveConflict called on a CKError that was not a serverRecordChanged error. The error was %{public}@ " ,
32- log: . default,
33- type: . fault,
34- String ( describing: effectiveError) )
31+ ckLog. fault ( " resolveConflict called on a CKError that was not a serverRecordChanged error. The error was \( String ( describing: effectiveError) , privacy: . public) " )
3532 return nil
3633 }
3734
3835 guard let clientRecord = effectiveError. userInfo [ CKRecordChangedErrorClientRecordKey] as? CKRecord else {
39- os_log ( " Failed to obtain client record from serverRecordChanged error. The error was %{public}@ " ,
40- log: . default,
41- type: . fault,
42- String ( describing: effectiveError) )
36+ ckLog. fault ( " Failed to obtain client record from serverRecordChanged error. The error was \( String ( describing: effectiveError) , privacy: . public) " )
4337 return nil
4438 }
4539
4640 guard let serverRecord = effectiveError. userInfo [ CKRecordChangedErrorServerRecordKey] as? CKRecord else {
47- os_log ( " Failed to obtain server record from serverRecordChanged error. The error was %{public}@ " ,
48- log: . default,
49- type: . fault,
50- String ( describing: effectiveError) )
41+ ckLog. fault ( " Failed to obtain server record from serverRecordChanged error. The error was \( String ( describing: effectiveError) , privacy: . public) " )
5142 return nil
5243 }
5344
5445 return resolver ( clientRecord, serverRecord)
5546 }
5647
57- @discardableResult func retryCloudKitOperationIfPossible( _ log: OSLog ? = nil , in queue: DispatchQueue = . main, with block: @escaping ( ) -> Void ) -> Bool {
58- let effectiveLog = log ?? . default
48+ @discardableResult func retryCloudKitOperationIfPossible( _ log: Logger ? = nil , in queue: DispatchQueue = . main, with block: @escaping ( ) -> Void ) -> Bool {
49+ let effectiveLog : Logger = log ?? ckLog
5950
6051 guard let effectiveError = self as? CKError else { return false }
6152
6253 guard let retryDelay = effectiveError. retryAfterSeconds else {
63- os_log ( " Error is not recoverable " , log : effectiveLog , type : . error )
54+ effectiveLog . error ( " Error is not recoverable " )
6455 return false
6556 }
6657
67- os_log ( " Error is recoverable. Will retry after %{public}f seconds " , log : effectiveLog , type : . error , retryDelay )
58+ effectiveLog . error ( " Error is recoverable. Will retry after \( retryDelay ) seconds " )
6859
6960 queue. asyncAfter ( deadline: . now( ) + retryDelay) {
7061 block ( )
0 commit comments