Skip to content

Commit

Permalink
Use structured logging (metadata) when logging queries (#110)
Browse files Browse the repository at this point in the history
* Don't log double `[]`s when logging queries.

* Use logging metadata for logging queries
  • Loading branch information
gwynne authored May 29, 2024
1 parent 8d3abe7 commit f35a863
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/SQLiteKit/SQLiteConnection+SQLKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions Sources/SQLiteKit/SQLiteConnectionSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit f35a863

Please sign in to comment.