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

feat: extend database logger context #165

Merged
merged 8 commits into from
Mar 27, 2024
Merged

Conversation

lotyp
Copy link
Member

@lotyp lotyp commented Mar 19, 2024

Changes

  • Introduced additional options in DriverConfig for detailed logging control: logInterpolatedQueries. Converts query into interpolated one. (Before change, this was done using logQueryParameters)

  • logQueryParameters - Now, does, what variable name says — Logs query parameters as array

  • Modified statement method in Driver.php to utilize new logging options, enriching log context with driver details and query parameters.

Rationale

These changes aim to improve the ORM's debugging and monitoring capabilities by offering detailed and configurable logging insights.

Checklist

  • Closes # -
  • How was this tested:
    • Added new tests to cover context parameters and driver

    • Created example application with sample entity, fired persist to get logger output, which now looks like this:

      • When logInterpolatedQueries => true and logQueryParameters' => true:
        [2024-03-19 21:42:14] local.INFO: INSERT INTO "posts" ("title", "content", "views", "id") VALUES ('title', 'content', 123, '018e58aa-38f9-725a-92cd-e69309ac5424') {"driver":"SQLite","elapsed":0.0006749629974365234,"rowCount":1,"parameters":["'title'","'content'","123","'018e58aa-38f9-725a-92cd-e69309ac5424'"]}
      
    • When logInterpolatedQueries => false and logQueryParameters' => true:

        [2024-03-19 21:52:20] local.INFO: INSERT INTO "posts" ("title", "content", "views", "id") VALUES (?, ?, ?, ?) {"driver":"SQLite","elapsed":0.0006299018859863281,"rowCount":1,"parameters":["'title'","'content'","123","'018e58b3-7727-7185-9b1a-b8993069a367'"]}
      
    • Default behavior (both parameters set to false):

        [2024-03-19 21:54:17] local.INFO: INSERT INTO "posts" ("title", "content", "views", "id") VALUES (?, ?, ?, ?) {"driver":"SQLite","elapsed":0.0006580352783203125,"rowCount":1}
      

@lotyp lotyp marked this pull request as draft March 19, 2024 18:38
@lotyp lotyp marked this pull request as ready for review March 19, 2024 22:04
@roxblnfk roxblnfk requested review from roxblnfk and msmakouz and removed request for roxblnfk March 19, 2024 22:37
Copy link

codecov bot commented Mar 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.24%. Comparing base (331a168) to head (1332047).

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x     #165      +/-   ##
============================================
+ Coverage     95.23%   95.24%   +0.01%     
- Complexity     1833     1836       +3     
============================================
  Files           130      130              
  Lines          5054     5066      +12     
============================================
+ Hits           4813     4825      +12     
  Misses          241      241              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/Query/Interpolator.php Outdated Show resolved Hide resolved
src/Driver/Driver.php Outdated Show resolved Hide resolved
src/Query/Interpolator.php Outdated Show resolved Hide resolved
lotyp added 2 commits March 27, 2024 02:39
Default Value for `$parameters` — The `$parameters` argument now defaults to an empty array ([]). This ensures that it's always iterable, making the function more predictable and eliminating the need for null checks before iterating over $parameters.
Copy link
Member

@roxblnfk roxblnfk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@msmakouz msmakouz merged commit 851e8ed into cycle:2.x Mar 27, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Released
Development

Successfully merging this pull request may close these issues.

3 participants