Repository navigation
Adding support for logging via swift-log #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
51af45a
b1fe893
820cf64
085652f
924969a
c498491
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -53,6 +53,10 @@ let package = Package( | |||||
| description: "Introduce SQLiteData conformances to the swift-tagged package." | ||||||
| ), | ||||||
| .trait( | ||||||
| name: "SQLiteDataSwiftLog", | ||||||
| description: "Use swift-log instead of OSLog for logging." | ||||||
| ), | ||||||
| .trait( | ||||||
| name: "SQLiteDataTagged", | ||||||
| description: "A deprecated alias for the 'Tagged' trait.", | ||||||
| enabledTraits: ["Tagged"] | ||||||
|
|
@@ -87,6 +91,7 @@ let package = Package( | |||||
| ] | ||||||
| ), | ||||||
| .package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.10.0"), | ||||||
| .package(url: "https://github.com/apple/swift-log", from: "1.6.0") | ||||||
| ], | ||||||
| targets: [ | ||||||
| .target( | ||||||
|
|
@@ -106,6 +111,11 @@ let package = Package( | |||||
| package: "swift-tagged", | ||||||
| condition: .when(traits: ["Tagged"]) | ||||||
| ), | ||||||
| .product( | ||||||
| name: "Logging", | ||||||
| package: "swift-log", | ||||||
| condition: .when(traits: ["SQLiteDataSwiftLog"]) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ) | ||||||
| ] | ||||||
| ), | ||||||
| .target( | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,47 @@ | ||||||||
| #if DEBUG && canImport(CloudKit) | ||||||||
| #if canImport(CloudKit) | ||||||||
|
|
||||||||
| #if SQLiteDataSwiftLog | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| @_exported import struct Logging.Logger | ||||||||
| import protocol Logging.LogHandler | ||||||||
|
Comment on lines
+4
to
+5
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to export or qualify these imports? Can we simply do:
Suggested change
|
||||||||
|
|
||||||||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||||||||
| extension SyncEngine { | ||||||||
| public typealias Logger = Logging.Logger | ||||||||
| } | ||||||||
|
|
||||||||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||||||||
| extension SyncEngine.Logger { | ||||||||
| public static var `default`: SyncEngine.Logger { | ||||||||
| .init(label: "SQLiteData") | ||||||||
| } | ||||||||
| public static var disabled: SyncEngine.Logger { | ||||||||
| .init(label: "SQLiteData") { _ in DisabledLogHandler() } | ||||||||
| } | ||||||||
| } | ||||||||
| #else | ||||||||
| @_exported import struct os.Logger | ||||||||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||||||||
| extension SyncEngine { | ||||||||
| public typealias Logger = os.Logger | ||||||||
| } | ||||||||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||||||||
| extension SyncEngine.Logger { | ||||||||
| public static var `default`: SyncEngine.Logger { | ||||||||
| .init(subsystem: "SQLiteData", category: "CloudKit") | ||||||||
| } | ||||||||
| public static var disabled: SyncEngine.Logger { | ||||||||
| .init(.disabled) | ||||||||
| } | ||||||||
| } | ||||||||
| #endif | ||||||||
|
|
||||||||
| #if DEBUG | ||||||||
| import CloudKit | ||||||||
| import TabularData | ||||||||
| import os | ||||||||
|
|
||||||||
| @available(iOS 17, macOS 14, tvOS 17, watchOS 10, *) | ||||||||
| extension Logger { | ||||||||
| extension SyncEngine.Logger { | ||||||||
| func log(_ event: SyncEngine.Event, syncEngine: any SyncEngineProtocol) { | ||||||||
| let prefix = "SQLiteData (\(syncEngine.database.databaseScope.label).db)" | ||||||||
| var actions: [String] = [] | ||||||||
|
|
@@ -302,3 +339,25 @@ | |||||||
| } | ||||||||
| } | ||||||||
| #endif | ||||||||
|
|
||||||||
| #if SQLiteDataSwiftLog | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| struct DisabledLogHandler: Logging.LogHandler { | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be
Suggested change
|
||||||||
| var logLevel: Logging.Logger.Level = .info | ||||||||
| var metadata: Logging.Logger.Metadata = [:] | ||||||||
| subscript(metadataKey key: String) -> Logging.Logger.Metadata.Value? { | ||||||||
| get { self.metadata[key] } | ||||||||
| set { self.metadata[key] = newValue } | ||||||||
| } | ||||||||
| func log( | ||||||||
| level: Logging.Logger.Level, | ||||||||
| message: Logging.Logger.Message, | ||||||||
| metadata: Logging.Logger.Metadata?, | ||||||||
| source: String, | ||||||||
| file: String, | ||||||||
| function: String, | ||||||||
| line: UInt | ||||||||
| ) {} | ||||||||
| } | ||||||||
| #endif | ||||||||
|
|
||||||||
| #endif | ||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -99,8 +99,7 @@ | |||||
| defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"), | ||||||
| startImmediately: Bool? = nil, | ||||||
| delegate: (any SyncEngineDelegate)? = nil, | ||||||
| logger: Logger = isTesting | ||||||
| ? Logger(.disabled) : Logger(subsystem: "SQLiteData", category: "CloudKit") | ||||||
| logger: Logger = isTesting ? Logger.disabled : Logger.default | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be abbreviated?
Suggested change
|
||||||
| ) throws | ||||||
| where | ||||||
| repeat (each T1).PrimaryKey.QueryOutput: IdentifierStringConvertible, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPM has converged on a simpler naming convention here: