-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
feature: Add OFF log level to StandardEnvironment #3904
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @gchaperon!
No behavioral change is too small for a test case :). See spoon.test.logging.LogTest
. It shouldn't be too hard to verify that no message gets logged for any logging level if the level is set to OFF
. You can draw inspiration from the testAllLevelsForLogs
test case (see how it captures the logging output).
@@ -274,7 +274,7 @@ public void report(Processor<?> processor, Level level, String message) { | |||
} | |||
|
|||
private void print(String message, Level messageLevel) { | |||
if (messageLevel.toInt() <= this.level.toInt()) { | |||
if (this.level.compareTo(Level.OFF) > 0 && messageLevel.toInt() <= this.level.toInt()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is more clear?
if (this.level.compareTo(Level.OFF) > 0 && messageLevel.toInt() <= this.level.toInt()) { | |
if (this.level != Level.OFF && messageLevel.toInt() <= this.level.toInt()) { |
I think it's a bit easier to read as it doesn't require one to go check the declaration order of the Level
values. This is probably a matter of preference, though, if you prefer your solution feel free to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there's a tiny behavioral difference: level != Level.OFF
will cause the if-block not to be entered even if the passed level is OFF
, whereas your original solution will cause it to be entered (but do nothing as no case in the switch matches)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, that's better, I didn't know enums could compare like that (that's how little java I know 😅)
hi! I changed the line following your advice and added a test. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks very good! The placement of the test is correct. The old JUnit4 parameterization is awkward because it parameterizes the entire class, which is why a nested class is needed for the non-parameterized tests.
JUnit5 parameterization is far less confusing (very easy to apply to just a single test).
Anyway, I just had a single comment in that we typically try to put a contract at the top of the test, stating what the test should do. See for example testMavenLauncherLogs
(and my comment).
@Test | ||
public void testLoggingOff() { | ||
final TestLogger logger = TestLoggerFactory.getTestLogger(Launcher.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a contract as a comment at the top of the test method? I.e. a comment stating what the test should do along, like so (ofc replacing my nonsense text):
@Test | |
public void testLoggingOff() { | |
final TestLogger logger = TestLoggerFactory.getTestLogger(Launcher.class); | |
@Test | |
public void testLoggingOff() { | |
// contract: The logger should do X given Y and perhaps Z | |
final TestLogger logger = TestLoggerFactory.getTestLogger(Launcher.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aahrg, I saw you had this convention, but then forgot to add one
I just fixed it
there, I just added a contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one final thing, there are a couple of redundant imports in LogTest
, probably added automatically by your IDE when you were trying stuff out. I missed them before, sorry!
After that I'm satisfied and we ping an integrator :)
import spoon.processing.Processor; | ||
import spoon.reflect.declaration.CtElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two imports seem redundant.
import spoon.processing.Processor; | |
import spoon.reflect.declaration.CtElement; |
That is exactly what happened, thanks for the notice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gchaperon Looks very good to me!
Ping @monperrus for workflow activation
Oh, and @gchaperon change the title from |
Thanks a lot @gchaperon for your first contribution in Spoon. |
also thanks for the guidance and patience! |
You're very welcome, we're always super happy to help new (or existing, some things are hard!) contributors in completing their PRs :) |
As discussed in #3901, this PR adds a new logging level
OFF(0)
and modifies the printing logic inStandardEnvironment
so that it is turned off if this new level is set.I tagged this as a feature following the tag of the issue.
The contributing guidelines state that feature PR should have tests and corresponding documentation. I though this PR is maybe to small for that, but please let me know if you would like tests added and what should they cover.