@@ -44,6 +44,7 @@ final class GRDBTests: XCTestCase {
4444 private var database : PowerSyncDatabaseProtocol !
4545 private var schema : Schema !
4646 private var pool : DatabasePool !
47+ private var logs : TestLogWriterAdapter !
4748
4849 override func setUp( ) async throws {
4950 try await super. setUp ( )
@@ -83,10 +84,13 @@ final class GRDBTests: XCTestCase {
8384 configuration: config
8485 )
8586
87+ logs = TestLogWriterAdapter ( )
88+ let logger = DefaultLogger ( minSeverity: LogSeverity . debug, writers: [ logs] )
8689 database = openPowerSyncWithGRDB (
8790 pool: pool,
8891 schema: schema,
89- identifier: dbIdentifier
92+ identifier: dbIdentifier,
93+ logger: DatabaseLogger ( logger)
9094 )
9195
9296 try await database. disconnectAndClear ( )
@@ -417,4 +421,37 @@ final class GRDBTests: XCTestCase {
417421 await fulfillment ( of: [ expectation] , timeout: 5 )
418422 watchTask. cancel ( )
419423 }
424+
425+ func testCustomLogger( ) async throws {
426+ try await database. get ( " SELECT 1 " , mapper: { row in } )
427+
428+ let warningIndex = logs. getLogs ( ) . firstIndex (
429+ where: { value in
430+ value. contains ( " debug: PowerSyncVersion " )
431+ }
432+ )
433+
434+ XCTAssert ( warningIndex! >= 0 )
435+ }
436+ }
437+
438+ final class TestLogWriterAdapter : LogWriterProtocol ,
439+ // The shared state is guarded by the DispatchQueue
440+ @unchecked Sendable
441+ {
442+ private let queue = DispatchQueue ( label: " TestLogWriterAdapter " )
443+
444+ private var logs = [ String] ( )
445+
446+ func getLogs( ) -> [ String ] {
447+ queue. sync {
448+ logs
449+ }
450+ }
451+
452+ func log( severity: LogSeverity , message: String , tag: String ? ) {
453+ queue. sync {
454+ logs. append ( " \( severity) : \( message) \( tag != nil ? " \( tag!) " : " " ) " )
455+ }
456+ }
420457}
0 commit comments