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

qa: address PMD GuardLogStatement warnings #5209

Merged
merged 30 commits into from
May 17, 2024
Merged

qa: address PMD GuardLogStatement warnings #5209

merged 30 commits into from
May 17, 2024

Conversation

soloturn
Copy link
Contributor

@soloturn soloturn commented Jan 29, 2024

using fluent logger avoids evaluating methods, and fixes the PMD warning: log not surrounded by "if". this is in case the argument to a parameterized logger is a method call, like here:

- logger.error("onAudioEnd() notification failed for {}", entry.getValue(), e);
+ logger.atError().addArgument(() -> entry.getValue()).addArgument(e).log("onAudioEnd() notification failed for {}");

Edit by niruandaleth/jdrueckert:
PMD warnings were fixed in different ways, among others the following variant of the fluent API which is less verbose than the one originally proposed (see above):

- logger.error("onAudioEnd() notification failed for {}", entry.getValue(), e);
+ logger.atError().log("onAudioEnd() notification failed for {}", entry.getValue(), e);

@soloturn soloturn requested a review from BenjaminAmos January 29, 2024 05:29
@BenjaminAmos
Copy link
Contributor

This might take a while to review (92 files changed) but at a cursory glance there's a few questions that occurred to me about this:

  • For the PMD warning (log not surrounded by "if"), is this about still evaluating methods even when logging is disabled? Is there a significant impact already from not doing this?
  • The "fluent" logger style appears more verbose and makes logging harder to distinguish from existing code. Is this to be used everywhere or just where a method is called for a log parameter?
  • How would you suggest we enforce this change? I suspect that new code will bring new log statements and they are highly likely to use the original logger methods unless enforced.

@soloturn
Copy link
Contributor Author

soloturn commented Feb 3, 2024

  • For the PMD warning (log not surrounded by "if"), is this about still evaluating methods even when logging is disabled? Is there a significant impact already from not doing this?

true. methods still would be called. depending which method it is the impact varies. not calling the method when not logging has, contrary, a clear and predictable impact: no code executed. which is good.

  • The "fluent" logger style appears more verbose and makes logging harder to distinguish from existing code. Is this to be used everywhere or just where a method is called for a log parameter?

i changed it only where a method is called as log parameter and pmd warned.

  • How would you suggest we enforce this change? I suspect that new code will bring new log statements and they are highly likely to use the original logger methods unless enforced.

we could turn on pmd again, it warns or blocks depending how we set it. there is no problem to use original logger methods, at least imo. there are other opinionated approaches, like using google flogger, which would convert everything, but that might be too much for terasology. personally i would not enforce it, but rely on peoples working brains on code review. as well as local gradle clean build warning about it. but that is not my call, i am happy with any approach you guys take.

@soloturn
Copy link
Contributor Author

soloturn commented Feb 3, 2024

This might take a while to review (92 files changed)

you find it easier to chunk it?

Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

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

Note: only reviewed roughly half the files so far. Need to get back to the rest.
Feel free to already apply the requested changes meanwhile.

General assumption: cases in which we want to disable logging completely are extremely rare, so we mainly want to avoid method evaluation in debug logs considering that the typical default log level will be info resulting in error, warning, and info logs being written.

Cases where we want to ignore the PMD warnings instead of using Fluent API to avoid additional verbosity leading to code being harder to read:

  • logs in catch clauses -> limited method evaluation
  • logs in dedicated warning/error/log methods -> intention of these methods is to write logs; if at all, calling these methods should be guarded
  • logs with simple getter methods

Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

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

more review comments along the same lines as the previous

@soloturn soloturn force-pushed the qa/fluent-logger branch 3 times, most recently from 7cf5139 to d203bc6 Compare February 15, 2024 17:52
@soloturn soloturn requested a review from jdrueckert February 15, 2024 17:52
Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

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

Finally done with all files. Please re-request a review once you implemented all requested changes 🙂

@soloturn soloturn force-pushed the qa/fluent-logger branch 2 times, most recently from 656055c to 5c7fa2c Compare February 24, 2024 20:04
@soloturn soloturn requested a review from jdrueckert February 25, 2024 14:49
@soloturn soloturn force-pushed the qa/fluent-logger branch 6 times, most recently from e5e0e41 to b34da80 Compare March 3, 2024 07:51
@jdrueckert jdrueckert added this to the 2023 Revive - Milestone 3 milestone Apr 21, 2024
@jdrueckert jdrueckert self-assigned this Apr 21, 2024
@soloturn soloturn force-pushed the qa/fluent-logger branch from aa488bc to cf50c8e Compare May 13, 2024 02:36
@soloturn soloturn dismissed jdrueckert’s stale review May 13, 2024 03:33

addressed most of the stuff. a couple were requesting a functional code change which is not part of a pull request writing log statements different.

Copy link
Member

@jdrueckert jdrueckert left a comment

Choose a reason for hiding this comment

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

@soloturn I went through all files again, applied the requested changes that you resolved without actually applying them. I also refactored your changes to use the less verbose variant of the fluent API that was discussed a while ago in our group sync.

From my pov this is good to go now, so I'm approving it.

For future reference two comments:

  1. Please try avoid force pushes as they can remove review comments. Force pushes are rarely necessary, usually merging upstream changes or the most recent main branch state in should be sufficient.
  2. Code refactorings (please don't confuse them with functional changes: introducing a local variable and referencing it does not modify the code's functionality) are fine when addressing code scanner findings.

While writing this second point and remembering your last comment on this PR, I also want to share an observation:
Based on the discussions we had during the work on our last milestone, I expected this PR to be about addressing code scanner findings (in particular PMD GuardLogStatement warnings).
According to your comment, in which you state that this PR is about "writing log statements different", you seem to have a different intent here, though. An intent I didn't suspect, especially in the light of the group discussions where everybody except yourself voiced concerns about the verbosity of the fluent API variant you wanted to switch to...

Maybe this was our main misunderstanding here.

Anyway, this PR is approved now, so feel free to merge it.

@jdrueckert jdrueckert changed the title fluent logger qa: address PMD GuardLogStatement warnings May 17, 2024
@soloturn soloturn merged commit 0c00a08 into develop May 17, 2024
10 checks passed
@soloturn soloturn deleted the qa/fluent-logger branch June 30, 2024 18:23
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.

3 participants