vapor / postgres-kit

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
MIT License
188 stars 70 forks source link

Use logging metadata when logging queries #266

Closed gwynne closed 5 months ago

gwynne commented 5 months ago

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
codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #266 +/- ## ======================================= Coverage 40.85% 40.85% ======================================= Files 13 13 Lines 842 842 ======================================= Hits 344 344 Misses 498 498 ``` | [Files](https://app.codecov.io/gh/vapor/postgres-kit/pull/266?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor) | Coverage Δ | | |---|---|---| | [Sources/PostgresKit/PostgresDatabase+SQL.swift](https://app.codecov.io/gh/vapor/postgres-kit/pull/266?src=pr&el=tree&filepath=Sources%2FPostgresKit%2FPostgresDatabase%2BSQL.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc0tpdC9Qb3N0Z3Jlc0RhdGFiYXNlK1NRTC5zd2lmdA==) | `72.72% <100.00%> (ø)` | |