From 8cced42fb2cdbe1d0864ca6c576d81d4cb8dcb49 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 28 Jan 2020 21:06:48 +0100 Subject: [PATCH] Use local LoggerContext in Log4jLog when static field not initialized yet Closes gh-24440 --- .../main/java/org/apache/commons/logging/LogAdapter.java | 9 +++++++-- 1 file changed, 7 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 d84b54e874e3..e6d6f42f0f36 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-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -157,7 +157,12 @@ private static class Log4jLog implements Log, Serializable { private final ExtendedLogger logger; public Log4jLog(String name) { - this.logger = loggerContext.getLogger(name); + LoggerContext context = loggerContext; + if (context == null) { + // Circular call in early-init scenario -> static field not initialized yet + context = LogManager.getContext(Log4jLog.class.getClassLoader(), false); + } + this.logger = context.getLogger(name); } @Override