Browse Source

Log4jLog re-resolves ExtendedLogger on deserialization

This is necessary for compatibility with Log4J 2.21, analogous to the existing re-resolution in Spring's SLF4J adapter.

Closes gh-31582
6.0.x
Juergen Hoeller 11 months ago
parent
commit
1e78cc35e5
  1. 9
      spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java

9
spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java

@ -145,9 +145,12 @@ final class LogAdapter { @@ -145,9 +145,12 @@ final class LogAdapter {
private static final LoggerContext loggerContext =
LogManager.getContext(Log4jLog.class.getClassLoader(), false);
private final ExtendedLogger logger;
private final String name;
private final transient ExtendedLogger logger;
public Log4jLog(String name) {
this.name = name;
LoggerContext context = loggerContext;
if (context == null) {
// Circular call in early-init scenario -> static field not initialized yet
@ -261,6 +264,10 @@ final class LogAdapter { @@ -261,6 +264,10 @@ final class LogAdapter {
this.logger.logIfEnabled(FQCN, level, null, message, exception);
}
}
protected Object readResolve() {
return new Log4jLog(this.name);
}
}

Loading…
Cancel
Save