Skip to content
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

Use logging metadata when logging queries #266

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

gwynne
Copy link
Member

@gwynne gwynne commented May 28, 2024

These changes are now available in 2.13.5

When a query is executed, the actual SQL query and its accompanying array of bound parameters (if any) are now logged as structured metadata on the logger using a generic message, rather than the query and bindings being the message. This follows the recommended guidelines for logging in libraries. Credit goes to @MahdiBM for the original suggestion.

Before:

2024-05-29T00:00:00Z debug codes.vapor.fluent : database-id=psql [PostgresKit] SELECT * FROM foo WHERE a=$1 [["bar"]]

After:

2024-05-29T00:00:00Z debug codes.vapor.fluent : database-id=psql sql=SELECT * FROM foo WHERE a=$1 binds=["bar"] [PostgresKit] Executing query

@gwynne gwynne added enhancement New feature or request semver-patch Internal changes only labels May 28, 2024
@gwynne gwynne requested review from 0xTim, MahdiBM and ptoffy May 28, 2024 23:30
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.85%. Comparing base (75004d9) to head (817e53d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #266   +/-   ##
=======================================
  Coverage   40.85%   40.85%           
=======================================
  Files          13       13           
  Lines         842      842           
=======================================
  Hits          344      344           
  Misses        498      498           
Files Coverage Δ
Sources/PostgresKit/PostgresDatabase+SQL.swift 72.72% <100.00%> (ø)

@gwynne gwynne merged commit 0b72fa8 into main May 29, 2024
18 checks passed
@gwynne gwynne deleted the use-logging-metadata branch May 29, 2024 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-patch Internal changes only
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants