Skip to content

Improve parameter logging#5673

Merged
roji merged 1 commit intonpgsql:mainfrom
balazsmeszegeto:improve-parameter-logging
Nov 8, 2024
Merged

Improve parameter logging#5673
roji merged 1 commit intonpgsql:mainfrom
balazsmeszegeto:improve-parameter-logging

Conversation

@balazsmeszegeto
Copy link
Contributor

Show actual values of array-typed parameters, fixes #5342

inspired by: LogValuesFormatter from Microsoft.Extensions.Logging.Abstractions

@balazsmeszegeto
Copy link
Contributor Author

I added improvement for single commands.

I am somewhat uncertain about batch commands though, because I see in there are several tests verifying that parameters will always be logged as System.Object[]. So makes me wonder that was there a decision made not to log? But on the other hand, log state will still hold the actual values for each individual command in the batch. So we can leave it as is or also unwrap batch parameters to show actual values.

Let me know your thoughts!

@balazsmeszegeto
Copy link
Contributor Author

One further idea is to convert all parameters to string (not just arrays and nulls). I'm also happy to go that direction, but seems like a bigger change and this is my first contribution, so don't know what is the policy. I can also create another PR if you prefer keeping this one small

@balazsmeszegeto
Copy link
Contributor Author

Is there any way to improve the communication? We can potentially extend this change, but I'd need input from somebody with more experience with this project.

I searched if there are any contribution guidelines, project roadmaps or communication hub, but did not find anything, so I have to rely on what is happening here

@AndrewZu1337
Copy link

@balazsmeszegeto , is it possible to add NpgsqlDbType to message (like EF Core does if logging is enabled)? I think that could be useful.

@balazsmeszegeto
Copy link
Contributor Author

@AndrewZu1337 Certainly possible, but that might be out of scope. I'm happy to extend the scope though, just need approval from a maintainer

@balazsmeszegeto
Copy link
Contributor Author

Any comments from reviewers? @roji @vonzshik

@balazsmeszegeto
Copy link
Contributor Author

Anyone, please...?

@vonzshik
Copy link
Contributor

I'm very sorry for the wait. I actually was meaning to look at all open pr's we had (like for the last few months), but then real life stuff happened and I'm only now started to have some free time. Overall your pr looks fine, just a few minor things to discuss.

@balazsmeszegeto
Copy link
Contributor Author

Thanks for the feedback. I've implemented your suggestions (and extended the test)

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

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

LGTM. @roji @NinoFloris whenever any of you have time.

@balazsmeszegeto
Copy link
Contributor Author

Is something required from me?

@vonzshik
Copy link
Contributor

Is something required from me?

Don't think so, just other members of the team busy with other stuff (@roji is mostly working on docs for EFCore/EFCore.pg at the moment). Worst case scenario I'll merge it on my own just before the release.
Though you probably could rebase on the latest main just to make it a bit easier to merge.

@roji
Copy link
Member

roji commented Nov 8, 2024

@balazsmeszegeto apologies from me as well that this didn't receive more attention earlier.

In the interest of getting this into the 9.0 release (on Tuesday), I've gone ahead and done some cleanup and pushed a commit to this PR - it's mainly various insignificant code cleanup, and an extraction of all logging tests to their own test suite.

One thing I did change was the logging distinction between DBNull (which this PR logged as NULL) and null (which it logged as (null)); I don't think the distinction between these two is relevant in this context (it isn't in most others), so I changed both to simply log NULL. If there's some specific reason we should be logging them differently let me know.

@vonzshik can I get a quick review of my changes?

…rs, fixes npgsql#5342

inspired by: LogValuesFormatter from Microsoft.Extensions.Logging.Abstractions

Co-authored-by: Shay Rojansky <roji@roji.org>
@roji roji force-pushed the improve-parameter-logging branch from 68ee116 to 9a7ea8a Compare November 8, 2024 19:45
@roji roji enabled auto-merge (squash) November 8, 2024 19:45
@roji roji merged commit 91086e5 into npgsql:main Nov 8, 2024
@balazsmeszegeto balazsmeszegeto deleted the improve-parameter-logging branch November 8, 2024 20:32
@balazsmeszegeto
Copy link
Contributor Author

Okay, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve parameter logging

4 participants