From f35a863ecc2da5d563b836a9a696b148b0f4169f Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Wed, 29 May 2024 12:10:59 -0500 Subject: [PATCH] Use structured logging (metadata) when logging queries (#110) * Don't log double `[]`s when logging queries. * Use logging metadata for logging queries --- Sources/SQLiteKit/SQLiteConnection+SQLKit.swift | 4 ++-- Sources/SQLiteKit/SQLiteConnectionSource.swift | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Sources/SQLiteKit/SQLiteConnection+SQLKit.swift b/Sources/SQLiteKit/SQLiteConnection+SQLKit.swift index 02950bf..5bd69ce 100644 --- a/Sources/SQLiteKit/SQLiteConnection+SQLKit.swift +++ b/Sources/SQLiteKit/SQLiteConnection+SQLKit.swift @@ -218,7 +218,7 @@ struct SQLiteDatabaseVersion: SQLDatabaseReportedVersion { let (sql, rawBinds) = self.serialize(query) if let queryLogLevel = self.queryLogLevel { - self.logger.log(level: queryLogLevel, "\(sql) [\(rawBinds)]") + self.logger.log(level: queryLogLevel, "Executing query", metadata: ["sql": .string(sql), "binds": .array(rawBinds.map { .string("\($0)") })]) } let binds: [SQLiteData] @@ -244,7 +244,7 @@ struct SQLiteDatabaseVersion: SQLDatabaseReportedVersion { let (sql, rawBinds) = self.serialize(query) if let queryLogLevel = self.queryLogLevel { - self.logger.log(level: queryLogLevel, "\(sql) [\(rawBinds)]") + self.logger.log(level: queryLogLevel, "Executing query", metadata: ["sql": .string(sql), "binds": .array(rawBinds.map { .string("\($0)") })]) } try await self.database.query( diff --git a/Sources/SQLiteKit/SQLiteConnectionSource.swift b/Sources/SQLiteKit/SQLiteConnectionSource.swift index f946f36..e327a50 100644 --- a/Sources/SQLiteKit/SQLiteConnectionSource.swift +++ b/Sources/SQLiteKit/SQLiteConnectionSource.swift @@ -49,8 +49,7 @@ public struct SQLiteConnectionSource: ConnectionPoolSource, Sendable { on: eventLoop ).flatMap { conn in if self.configuration.enableForeignKeys { - return conn.query("PRAGMA foreign_keys = ON") - .map { _ in conn } + return conn.query("PRAGMA foreign_keys = ON").map { _ in conn } } else { return eventLoop.makeSucceededFuture(conn) }