Skip to content

Commit f97e819

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 (cherry picked from commit 1e78cc3)
1 parent f8e1ce3 commit f97e819

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -154,9 +154,12 @@ private static class Log4jLog implements Log, Serializable {
154154
private static final LoggerContext loggerContext =
155155
LogManager.getContext(Log4jLog.class.getClassLoader(), false);
156156

157-
private final ExtendedLogger logger;
157+
private final String name;
158+
159+
private final transient ExtendedLogger logger;
158160

159161
public Log4jLog(String name) {
162+
this.name = name;
160163
LoggerContext context = loggerContext;
161164
if (context == null) {
162165
// Circular call in early-init scenario -> static field not initialized yet
@@ -270,6 +273,10 @@ private void log(Level level, Object message, Throwable exception) {
270273
this.logger.logIfEnabled(FQCN, level, null, message, exception);
271274
}
272275
}
276+
277+
protected Object readResolve() {
278+
return new Log4jLog(this.name);
279+
}
273280
}
274281

275282

0 commit comments

Comments
 (0)