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

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

Closed
panbingkun opened this issue Mar 1, 2024 · 8 comments · Fixed by #2338 or #2340
Assignees
Labels
api Affects the public API bug Incorrect, unexpected, or unintended behavior of existing code
Milestone

Comments

@panbingkun
Copy link
Contributor

panbingkun commented Mar 1, 2024

Description

When we upgraded log4j2 from version 2.22.1 to 2.23.0 in Spark, we found that logs that could have been printed before are no longer being printed.

Configuration

# This log4j config file is for integration test SparkConfPropagateSuite.
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = console

appender.console.type = Console
appender.console.name = console
appender.console.target = SYSTEM_ERR
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss.SSS} %p %c: %maxLen{%m}{512}%n%ex{8}%n

Version: [Log4j version]
2.23.0

Operating system: [OS and version]
Ubuntu 22.04.4 LTS And macos Sonama 14.3.1.

JDK: [JDK distribution and version]
JDK 17

Logs

The following are the logs printed in version 2.22.1:

...

TRACE StatusLogger DefaultConfiguration cleaning Appenders from 1 LoggerConfigs.
DEBUG StatusLogger Stopped org.apache.logging.log4j.core.config.DefaultConfiguration@384ad17b OK
TRACE StatusLogger Reregistering MBeans after reconfigure. Selector=org.apache.logging.log4j.core.selector.ClassLoaderContextSelector@5852c06f
TRACE StatusLogger Reregistering context (1/1): '5ffd2b27' org.apache.logging.log4j.core.LoggerContext@31190526
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=StatusLogger'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=ContextSelector'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=Loggers,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=Appenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=AsyncAppenders,name=*'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=AsyncLoggerRingBuffer'
TRACE StatusLogger Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=5ffd2b27,component=Loggers,name=*,subtype=RingBuffer'
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=5ffd2b27
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=StatusLogger
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=ContextSelector
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=Loggers,name=
DEBUG StatusLogger Registering MBean org.apache.logging.log4j2:type=5ffd2b27,component=Appenders,name=console
TRACE StatusLogger Using default SystemClock for timestamps.
DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock supports precise timestamps.
TRACE StatusLogger Using DummyNanoClock for nanosecond timestamps.
DEBUG StatusLogger Reconfiguration complete for context[name=5ffd2b27] at URI /Users/yangjie01/Tools/4.0/spark-4.0.0-SNAPSHOT-bin-3.3.6/conf/log4j2.properties (org.apache.logging.log4j.core.LoggerContext@31190526) with optional ClassLoader: null
DEBUG StatusLogger Shutdown hook enabled. Registering a new one.
...

In version 2.23.0, StatusLogger related logs are no longer printed, eg

DEBUG StatusLogger Reconfiguration complete for context[name=5ffd2b27] at URI /Users/yangjie01/Tools/4.0/spark-4.0.0-SNAPSHOT-bin-3.3.6/conf/log4j2.properties (org.apache.logging.log4j.core.LoggerContext@31190526) with optional ClassLoader: null

The above logs will no longer be output.

Reproduction

The relevant upgrade PR in Spark is
apache/spark#45292

I found that it was caused by the following changes:

Is this change in line with our expectations? Or this is a bug?

@ppkarwasz ppkarwasz added the bug Incorrect, unexpected, or unintended behavior of existing code label Mar 1, 2024
@ppkarwasz ppkarwasz added this to the 2.23.1 milestone Mar 1, 2024
@ppkarwasz
Copy link
Contributor

@panbingkun,

In release 2.23.0 the StatusLogger was entirely rewritten to work around some circular dependency problems we were having.

This is clearly a bug (IMHO the implementation of StatusLogger#getLevel is faulty). Could you submit a PR?

@vy
Copy link
Member

vy commented Mar 1, 2024

@panbingkun, no need to submit a PR. I am taking care of this.

@panbingkun
Copy link
Contributor Author

@panbingkun,

In release 2.23.0 the StatusLogger was entirely rewritten to work around some circular dependency problems we were having.

This is clearly a bug (IMHO the implementation of StatusLogger#getLevel is faulty). Could you submit a PR?

Okay, thank you very much for your reply.
Let me wait for the next opportunity for the first submission of log4j2 😄

@panbingkun
Copy link
Contributor Author

@panbingkun, no need to submit a PR. I am taking care of this.

Thanks.

@vy
Copy link
Member

vy commented Mar 1, 2024

@panbingkun, I have merged the fix to 2.x branch. Could you give the 2.23.1-SNAPSHOT a try once this CI job successfully completes, and share the outcome, please?

@vy vy added the api Affects the public API label Mar 1, 2024
@panbingkun
Copy link
Contributor Author

panbingkun commented Mar 1, 2024

@panbingkun, I have merged the fix to 2.x branch. Could you give the 2.23.1-SNAPSHOT a try once this CI job successfully completes, and share the outcome, please?

Sure, let we to do it now.

@vy
Copy link
Member

vy commented Mar 1, 2024

Sure, let we to do it now.

@panbingkun, the CI job has successfully completed – needed a kick. Would you mind giving 2.23.1-SNAPSHOT a try and sharing the outcome, please?

@panbingkun
Copy link
Contributor Author

panbingkun commented Mar 2, 2024

Sure, let we to do it now.

@panbingkun, the CI job has successfully completed – needed a kick. Would you mind giving 2.23.1-SNAPSHOT a try and sharing the outcome, please?

@vy @ppkarwasz

After testing, it was found that it still did not output the expected log information.
I analyzed it and found that StatusLogger.isEnable is working well now, but the method StatusConsoleListener.log still seems to have some issues, as follows:

public void log(final StatusData data) {
requireNonNull(data, "data");
if (level.isLessSpecificThan(data.getLevel())) {
final String formattedStatus = data.getFormattedStatus();
stream.println(formattedStatus);
}
}

image

The above method does not consider whether the debugging mode is turned on,
So, I proposed a follow-up pr: #2340,
Because I only have a rough understanding of log4j2, if the above modifications are incorrect, please correct me. 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
3 participants