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
This commit is contained in:
@@ -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 {
|
||||
this.logger.logIfEnabled(FQCN, level, null, message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object readResolve() {
|
||||
return new Log4jLog(this.name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user