Skip to content

[FOLLOWUP] Fix StatusLogger log level filtering when debug mode is enabled - #2340

Merged
vy merged 3 commits into
apache:2.xfrom
panbingkun:2.x_fix_statuslogger_debugEnable
Mar 2, 2024
Merged

vy merged 3 commits into
apache:2.xfrom
panbingkun:2.x_fix_statuslogger_debugEnable

Conversation

@panbingkun

Copy link
Copy Markdown
Contributor

Follow up for #2338,
Fixes #2337 and makes StatusLogger take debug mode into account.

@panbingkun

Copy link
Copy Markdown
Contributor Author

cc @vy @ppkarwasz

public void log(final StatusData data) {
requireNonNull(data, "data");
if (level.isLessSpecificThan(data.getLevel())) {
if (debugEnabled || level.isLessSpecificThan(data.getLevel())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the correct fix is to remove the filtering on level here. StatusLogger is already taking care of the filtering, listeners should not (incorrectly!) duplicate that work. Hence, instead of leaking debugEnabled to StatusConsoleListener, could you remove this if block, please?

As a result of this change, StatusConsoleListenerTest#level_and_stream_should_be_honored test will be broken. Could you rename it to stream_should_be_honored and fix it too, please? There you won't need multiple messages with different levels anymore. Checking the dump of a single message should be good enough.

I can share some development tips to quickly iterate over your changes:

  • Compile your log4j-api changes: ./mvnw clean install -Dmaven.test.skip -Dspotless.skip -Dcyclonedx.skip -Dspotbugs.skip -Drat.skip -Dbnd.baseline.skip -pl :log4j-api
  • Make sure you fixed StatusConsoleListenerTest: ./mvnw test -Dspotless.skip -Dcyclonedx.skip -Dspotbugs.skip -Drat.skip -Dbnd.baseline.skip -pl :log4j-api-test -Dtest=StatusConsoleListenerTest
  • Fix formatting: ./mvnw spotless:apply -pl :log4j-api,:log4j-api-test
  • Make sure all is in good shape: ./mvnw clean install -pl :log4j-api,:log4j-api-test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, let me try making it.

@panbingkun

Copy link
Copy Markdown
Contributor Author

The local verification results are as follows:

...
2024-03-02T12:30:05.718720Z main DEBUG Registering MBean org.apache.logging.log4j2:type=5ffd2b27
2024-03-02T12:30:05.719599Z main DEBUG Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=StatusLogger
2024-03-02T12:30:05.719958Z main DEBUG Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=ContextSelector
2024-03-02T12:30:05.720390Z main DEBUG Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=Loggers,name=
2024-03-02T12:30:05.720736Z main DEBUG Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=Appenders,name=console
2024-03-02T12:30:05.721543Z main TRACE Using default SystemClock for timestamps.
2024-03-02T12:30:05.721726Z main DEBUG org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
2024-03-02T12:30:05.721839Z main TRACE Using DummyNanoClock for nanosecond timestamps.
2024-03-02T12:30:05.721929Z main DEBUG Reconfiguration complete for context[name=5ffd2b27] at URI /Users/panbingkun/Developer/spark/spark-client/spark-4.0.0-SNAPSHOT-bin-3.3.6/conf/log4j2.properties (org.apache.logging.log4j.core.LoggerContext@3857f613) with optional ClassLoader: null
2024-03-02T12:30:05.721979Z main DEBUG Shutdown hook enabled. Registering a new one.
2024-03-02T12:30:05.722241Z main DEBUG LoggerContext[name=5ffd2b27, org.apache.logging.log4j.core.LoggerContext@3857f613] started OK.
2024-03-02T12:30:05.769692Z main TRACE Log4jLoggerFactory.getContext() found anchor interface org.apache.spark.internal.Logging
2024-03-02T12:30:05.849111Z main TRACE Log4jLoggerFactory.getContext() found anchor class org.apache.spark.network.util.JavaUtils
2024-03-02T12:30:05.951557Z main TRACE Log4jLoggerFactory.getContext() found anchor class org.apache.hadoop.conf.Configuration
2024-03-02T12:30:05.951733Z main TRACE Log4jLoggerFactory.getContext() found anchor class org.apache.hadoop.conf.Configuration
2024-03-02T12:30:05.957285Z main TRACE Log4jLoggerFactory.getContext() found anchor class org.apache.hadoop.util.Preconditions
2024-03-02T12:30:05.998250Z main TRACE Log4jLoggerFactory.getContext() found anchor interface org.apache.spark.internal.Logging
2024-03-02T12:30:05.999710Z main DEBUG AsyncLogger.ThreadNameStrategy=UNCACHED (user specified null, default is UNCACHED)
2024-03-02T12:30:05.999769Z main TRACE Using default SystemClock for timestamps.
2024-03-02T12:30:05.999811Z main DEBUG org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
...

It's okay.

@panbingkun
panbingkun requested a review from vy March 2, 2024 12:33

@ppkarwasz ppkarwasz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@vy vy self-assigned this Mar 2, 2024
@vy vy added bug Incorrect, unexpected, or unintended behavior of existing code api Affects the public API labels Mar 2, 2024
@vy vy added this to the 2.23.1 milestone Mar 2, 2024
@vy

vy commented Mar 2, 2024

Copy link
Copy Markdown
Member

Great job! 💯
Thanks @panbingkun! 🙇

@vy
vy merged commit 28b70d1 into apache:2.x Mar 2, 2024
@panbingkun

panbingkun commented Mar 3, 2024 •

Copy link
Copy Markdown
Contributor Author

Thank you very much for the help provided by @vy and @ppkarwasz
Also, may I friendly ask a question, do we have a planned release date for the official version 2.23.1?

@vy

vy commented Mar 4, 2024

Copy link
Copy Markdown
Member

do we have a planned release date for the official version 2.23.1?

Yes, it was last week, until you told us StatusLogger doesn't work. 😝 Putting joke aside, I think we will try again this week.

@panbingkun

Copy link
Copy Markdown
Contributor Author

do we have a planned release date for the official version 2.23.1?

Yes, it was last week, until you told us StatusLogger doesn't work. 😝 Putting joke aside, I think we will try again this week.

Haha.., thank you very much! ❤️

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

Labels

api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The parameter -Dlog4j2.debug does not take effect in version 2.23.0, and StatusLogger.debug will no longer print logs

3 participants