WIP: logging utilities

This commit is contained in:
John Rommel Estropia
2016-05-05 09:44:14 +08:00
parent 099dcfab68
commit 0073d038e0
46 changed files with 791 additions and 396 deletions

View File

@@ -46,11 +46,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to commit a \(typeName(self)) outside its designated queue."
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(typeName(self)) more than once."
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.isCommitted = true
@@ -75,11 +75,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue."
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to begin a child transaction from an already committed \(typeName(self))."
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
)
return SynchronousDataTransaction(
@@ -101,7 +101,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))."
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
)
return super.create(into)
@@ -118,7 +118,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))."
"Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
)
return super.edit(object)
@@ -136,7 +136,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))."
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
)
return super.edit(into, objectID)
@@ -151,7 +151,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))."
"Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
)
super.delete(object)
@@ -168,7 +168,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entities from an already committed \(typeName(self))."
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
)
super.delete(([object1, object2] + objects).flatMap { $0 })
@@ -183,7 +183,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entities from an already committed \(typeName(self))."
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
)
super.delete(objects)
@@ -208,7 +208,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.log(
.Warning,
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
@@ -224,7 +224,7 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.log(
.Warning,
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
@@ -244,11 +244,11 @@ public final class AsynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to rollback an already committed \(typeName(self))."
"Attempted to rollback an already committed \(cs_typeName(self))."
)
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to rollback a \(typeName(self)) outside its designated queue."
"Attempted to rollback a \(cs_typeName(self)) outside its designated queue."
)
self.context.reset()

View File

@@ -57,7 +57,7 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to create an entity of type \(typeName(T)) outside its designated queue."
"Attempted to create an entity of type \(cs_typeName(T)) outside its designated queue."
)
let context = self.context
@@ -72,10 +72,10 @@ public /*abstract*/ class BaseDataTransaction {
return object
case (nil, true):
fatalError("Attempted to create an entity of type \(typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.")
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) with ambiguous destination persistent store, but the configuration name was not specified.")
default:
fatalError("Attempted to create an entity of type \(typeName(entityClass)), but a destination persistent store containing the entity type could not be found.")
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)), but a destination persistent store containing the entity type could not be found.")
}
}
else {
@@ -90,11 +90,11 @@ public /*abstract*/ class BaseDataTransaction {
default:
if let configuration = into.configuration {
fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.")
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the configuration \"\(configuration)\", which it doesn't belong to.")
}
else {
fatalError("Attempted to create an entity of type \(typeName(entityClass)) into the default configuration, which it doesn't belong to.")
fatalError("Attempted to create an entity of type \(cs_typeName(entityClass)) into the default configuration, which it doesn't belong to.")
}
}
}
@@ -111,7 +111,7 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to update an entity of type \(typeName(object)) outside its designated queue."
"Attempted to update an entity of type \(cs_typeName(object)) outside its designated queue."
)
guard let object = object else {
@@ -132,12 +132,12 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.isRunningInAllowedQueue(),
"Attempted to update an entity of type \(typeName(T)) outside its designated queue."
"Attempted to update an entity of type \(cs_typeName(T)) outside its designated queue."
)
CoreStore.assert(
into.inferStoreIfPossible
|| (into.configuration ?? Into.defaultConfigurationName) == objectID.persistentStore?.configurationName,
"Attempted to update an entity of type \(typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
"Attempted to update an entity of type \(cs_typeName(T)) but the specified persistent store do not match the `NSManagedObjectID`."
)
return self.fetchExisting(objectID) as? T
}
@@ -214,11 +214,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access inserted objects from a \(typeName(self)) outside its designated queue."
"Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access inserted objects from an already committed \(typeName(self))."
"Attempted to access inserted objects from an already committed \(cs_typeName(self))."
)
return self.context.insertedObjects
@@ -235,11 +235,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access inserted objects from a \(typeName(self)) outside its designated queue."
"Attempted to access inserted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access inserted objects from an already committed \(typeName(self))."
"Attempted to access inserted objects from an already committed \(cs_typeName(self))."
)
return Set(self.context.insertedObjects.flatMap { $0 as? T })
@@ -255,11 +255,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access inserted objects IDs from an already committed \(typeName(self))."
"Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.insertedObjects.map { $0.objectID })
@@ -276,11 +276,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access inserted object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access inserted object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access inserted objects IDs from an already committed \(typeName(self))."
"Attempted to access inserted objects IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.insertedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })
@@ -296,11 +296,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access updated objects from a \(typeName(self)) outside its designated queue."
"Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access updated objects from an already committed \(typeName(self))."
"Attempted to access updated objects from an already committed \(cs_typeName(self))."
)
return self.context.updatedObjects
@@ -317,11 +317,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access updated objects from a \(typeName(self)) outside its designated queue."
"Attempted to access updated objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access updated objects from an already committed \(typeName(self))."
"Attempted to access updated objects from an already committed \(cs_typeName(self))."
)
return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T })
@@ -337,11 +337,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access updated object IDs from an already committed \(typeName(self))."
"Attempted to access updated object IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.updatedObjects.map { $0.objectID })
@@ -358,11 +358,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access updated object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access updated object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access updated object IDs from an already committed \(typeName(self))."
"Attempted to access updated object IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.updatedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })
@@ -378,11 +378,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access deleted objects from a \(typeName(self)) outside its designated queue."
"Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access deleted objects from an already committed \(typeName(self))."
"Attempted to access deleted objects from an already committed \(cs_typeName(self))."
)
return self.context.deletedObjects
@@ -399,11 +399,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access deleted objects from a \(typeName(self)) outside its designated queue."
"Attempted to access deleted objects from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access deleted objects from an already committed \(typeName(self))."
"Attempted to access deleted objects from an already committed \(cs_typeName(self))."
)
return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0 as! T })
@@ -420,11 +420,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access deleted object IDs from an already committed \(typeName(self))."
"Attempted to access deleted object IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.deletedObjects.map { $0.objectID })
@@ -441,11 +441,11 @@ public /*abstract*/ class BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to access deleted object IDs from a \(typeName(self)) outside its designated queue."
"Attempted to access deleted object IDs from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to access deleted object IDs from an already committed \(typeName(self))."
"Attempted to access deleted object IDs from an already committed \(cs_typeName(self))."
)
return Set(self.context.deletedObjects.filter { $0.isKindOfClass(entity) }.map { $0.objectID })

View File

@@ -46,11 +46,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to commit a \(typeName(self)) outside its designated queue."
"Attempted to commit a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to commit a \(typeName(self)) more than once."
"Attempted to commit a \(cs_typeName(self)) more than once."
)
self.isCommitted = true
@@ -70,11 +70,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to begin a child transaction from a \(typeName(self)) outside its designated queue."
"Attempted to begin a child transaction from a \(cs_typeName(self)) outside its designated queue."
)
CoreStore.assert(
!self.isCommitted,
"Attempted to begin a child transaction from an already committed \(typeName(self))."
"Attempted to begin a child transaction from an already committed \(cs_typeName(self))."
)
return SynchronousDataTransaction(
@@ -96,7 +96,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to create an entity of type \(typeName(T)) from an already committed \(typeName(self))."
"Attempted to create an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
)
return super.create(into)
@@ -113,7 +113,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(typeName(object)) from an already committed \(typeName(self))."
"Attempted to update an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
)
return super.edit(object)
@@ -131,7 +131,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to update an entity of type \(typeName(T)) from an already committed \(typeName(self))."
"Attempted to update an entity of type \(cs_typeName(T)) from an already committed \(cs_typeName(self))."
)
return super.edit(into, objectID)
@@ -146,7 +146,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entity of type \(typeName(object)) from an already committed \(typeName(self))."
"Attempted to delete an entity of type \(cs_typeName(object)) from an already committed \(cs_typeName(self))."
)
super.delete(object)
@@ -163,7 +163,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entities from an already committed \(typeName(self))."
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
)
super.delete(([object1, object2] + objects).flatMap { $0 })
@@ -178,7 +178,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to delete an entities from an already committed \(typeName(self))."
"Attempted to delete an entities from an already committed \(cs_typeName(self))."
)
super.delete(objects)
@@ -204,7 +204,7 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.log(
.Warning,
message: "The closure for the \(typeName(self)) completed without being committed. All changes made within the transaction were discarded."
message: "The closure for the \(cs_typeName(self)) completed without being committed. All changes made within the transaction were discarded."
)
}
}
@@ -224,11 +224,11 @@ public final class SynchronousDataTransaction: BaseDataTransaction {
CoreStore.assert(
!self.isCommitted,
"Attempted to rollback an already committed \(typeName(self))."
"Attempted to rollback an already committed \(cs_typeName(self))."
)
CoreStore.assert(
self.transactionQueue.isCurrentExecutionContext(),
"Attempted to rollback a \(typeName(self)) outside its designated queue."
"Attempted to rollback a \(cs_typeName(self)) outside its designated queue."
)
self.context.reset()

View File

@@ -70,7 +70,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.supportsUndo,
"Attempted to rollback a \(typeName(self)) with Undo support disabled."
"Attempted to rollback a \(cs_typeName(self)) with Undo support disabled."
)
self.context.rollback()
}
@@ -82,7 +82,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.supportsUndo,
"Attempted to undo a \(typeName(self)) with Undo support disabled."
"Attempted to undo a \(cs_typeName(self)) with Undo support disabled."
)
self.context.undo()
}
@@ -94,7 +94,7 @@ public final class UnsafeDataTransaction: BaseDataTransaction {
CoreStore.assert(
self.supportsUndo,
"Attempted to redo a \(typeName(self)) with Undo support disabled."
"Attempted to redo a \(cs_typeName(self)) with Undo support disabled."
)
self.context.redo()
}