Add logging to DataFile.

This commit is contained in:
Brent Simmons 2024-06-15 11:50:40 -07:00
parent 5a02ba417f
commit 9227924f4e
2 changed files with 9 additions and 1 deletions

View File

@ -31,7 +31,6 @@ import Core
func markAsDirty() {
logger.info("OPMLFile marked dirty: \(self.fileURL)")
dataFile.markAsDirty()
}

View File

@ -29,6 +29,11 @@ public protocol DataFileDelegate: AnyObject {
private let fileURL: URL
private let saveQueue: CoalescingQueue
private static let logger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "DataFile")
private var logger: Logger {
Self.logger
}
public init(fileURL: URL) {
self.fileURL = fileURL
@ -38,14 +43,17 @@ public protocol DataFileDelegate: AnyObject {
public func markAsDirty() {
isDirty = true
logger.info("Data file marked dirty: \(self.fileURL)")
}
public func save() {
assert(Thread.isMainThread)
isDirty = false
logger.info("Saving data file: \(self.fileURL)")
guard let data = delegate?.data(for: self) else {
logger.error("Delegate did not return data for data file: \(self.fileURL)")
return
}
@ -53,6 +61,7 @@ public protocol DataFileDelegate: AnyObject {
try data.write(to: fileURL)
} catch {
delegate?.dataFileWriteToDiskDidFail(for: self, error: error)
logger.error("Data file did fail to write to disk: \(self.fileURL)")
}
}
}