Skip to content

[Logger] Support log4j-2.20+#471

Open
DriverSong wants to merge 1 commit into
ray-project:masterfrom
DriverSong:support_log4j_2.20+
Open

[Logger] Support log4j-2.20+#471
DriverSong wants to merge 1 commit into
ray-project:masterfrom
DriverSong:support_log4j_2.20+

Conversation

@DriverSong

Copy link
Copy Markdown

While log4j 2.20+ remove no-arg constructor from Log4jLoggerFactory and ray-2.54.0 use log4j 2.25.3, raydp should support the new constructor Log4jLoggerFactory(LoggerContext).

@slfan1989 slfan1989 requested a review from Copilot May 10, 2026 03:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the SLF4J binding initialization in RayDP’s agent to remain compatible with Log4j 2.20+, which removed the no-arg constructor from org.apache.logging.slf4j.Log4jLoggerFactory.

Changes:

  • Adds a reflective fallback path to instantiate Log4jLoggerFactory using the Log4jLoggerFactory(LoggerContext) constructor when no no-arg constructor is available.
  • Introduces reflection imports and logic to obtain a LoggerContext via LogManager.getContext(false).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 103 to +112
try {
tmpFactory = (ILoggerFactory) tempClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
// log4j 2.20+ removed the no-arg constructor from
// Log4jLoggerFactory. Fall back to the constructor that
// accepts a LoggerContext.
try {
Class<?> ctxClass = Class.forName(
"org.apache.logging.log4j.spi.LoggerContext");
Constructor<?> ctor = tempClass.getConstructor(ctxClass);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@DriverSong Please address this comment

.invoke(null, false);
tmpFactory = (ILoggerFactory) ctor.newInstance(ctx);
} catch (Exception ex) {
e.printStackTrace();
.invoke(null, false);
tmpFactory = (ILoggerFactory) ctor.newInstance(ctx);
} catch (Exception ex) {
e.printStackTrace();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

if we want to print e it should be print out of the inner try..catch.. Otherwise it is confusing

@pang-wu pang-wu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a new test matrix point for 2.54.0 as mentioned.

@my-vegetable-has-exploded

Copy link
Copy Markdown
Contributor

May be we can upgrade log4j-slf4j-impl to 2.25.3 as well.@DriverSong

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.

5 participants