From f97e819c9e55d9260df4f330d6a50f816a6b23de Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 9 Nov 2023 12:12:55 +0100 Subject: [PATCH] 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 1e78cc35e596a6927a6ae25418c5f043ee8c40aa) --- .../java/org/apache/commons/logging/LogAdapter.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java index cc5bed06ea93..0559f53ca078 100644 --- a/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java +++ b/spring-jcl/src/main/java/org/apache/commons/logging/LogAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -154,9 +154,12 @@ private static class Log4jLog implements Log, Serializable { 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 @@ -270,6 +273,10 @@ private void log(Level level, Object message, Throwable exception) { this.logger.logIfEnabled(FQCN, level, null, message, exception); } } + + protected Object readResolve() { + return new Log4jLog(this.name); + } }