Skip to content

Commit 1e78cc3

Browse files
committed
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
1 parent 11fdb5b commit 1e78cc3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ private static class Log4jLog implements Log, Serializable {
145145
private static final LoggerContext loggerContext =
146146
LogManager.getContext(Log4jLog.class.getClassLoader(), false);
147147

148-
private final ExtendedLogger logger;
148+
private final String name;
149+
150+
private final transient ExtendedLogger logger;
149151

150152
public Log4jLog(String name) {
153+
this.name = name;
151154
LoggerContext context = loggerContext;
152155
if (context == null) {
153156
// Circular call in early-init scenario -> static field not initialized yet
@@ -261,6 +264,10 @@ private void log(Level level, Object message, Throwable exception) {
261264
this.logger.logIfEnabled(FQCN, level, null, message, exception);
262265
}
263266
}
267+
268+
protected Object readResolve() {
269+
return new Log4jLog(this.name);
270+
}
264271
}
265272

266273

0 commit comments

Comments
 (0)