Skip to content

Commit 546e4fa

Browse files
committed
Merge branch '2.24.x' into 2.x
2 parents 52dbb47 + e65538d commit 546e4fa

File tree

9 files changed

+111
-9
lines changed

9 files changed

+111
-9
lines changed

log4j-api/src/main/java/org/apache/logging/log4j/spi/LoggerRegistry.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.concurrent.locks.Lock;
2929
import java.util.concurrent.locks.ReadWriteLock;
3030
import java.util.concurrent.locks.ReentrantReadWriteLock;
31+
import org.apache.logging.log4j.Logger;
3132
import org.apache.logging.log4j.message.MessageFactory;
3233
import org.apache.logging.log4j.message.ParameterizedMessageFactory;
3334
import org.jspecify.annotations.NullMarked;
@@ -246,7 +247,10 @@ public boolean hasLogger(final String name, final Class<? extends MessageFactory
246247

247248
/**
248249
* Registers the provided logger.
249-
* <b>Logger name and message factory parameters are ignored</b>, those will be obtained from the logger instead.
250+
* <p>
251+
* The logger will be registered using the keys provided by the {@code name} and {@code messageFactory} parameters
252+
* and the values of {@link Logger#getName()} and {@link Logger#getMessageFactory()}.
253+
* </p>
250254
*
251255
* @param name a logger name
252256
* @param messageFactory a message factory
@@ -263,9 +267,16 @@ public void putIfAbsent(final String name, @Nullable final MessageFactory messag
263267
try {
264268
final MessageFactory effectiveMessageFactory =
265269
messageFactory != null ? messageFactory : ParameterizedMessageFactory.INSTANCE;
270+
// Register using the keys provided by the caller
266271
loggerByMessageFactoryByName
267272
.computeIfAbsent(name, this::createLoggerRefByMessageFactoryMap)
268273
.putIfAbsent(effectiveMessageFactory, logger);
274+
// Also register using the values extracted from `logger`
275+
if (!name.equals(logger.getName()) || !effectiveMessageFactory.equals(logger.getMessageFactory())) {
276+
loggerByMessageFactoryByName
277+
.computeIfAbsent(logger.getName(), this::createLoggerRefByMessageFactoryMap)
278+
.putIfAbsent(logger.getMessageFactory(), logger);
279+
}
269280
} finally {
270281
writeLock.unlock();
271282
}

log4j-core/src/main/java/org/apache/logging/log4j/core/util/internal/InternalLoggerRegistry.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,24 @@ public Logger computeIfAbsent(
156156
// Create the logger
157157
logger = loggerSupplier.apply(name, messageFactory);
158158

159-
// Report message factory mismatches, if there is any
159+
// Report name and message factory mismatch if there are any
160+
final String loggerName = logger.getName();
160161
final MessageFactory loggerMessageFactory = logger.getMessageFactory();
161162
if (!loggerMessageFactory.equals(messageFactory)) {
162163
StatusLogger.getLogger()
163164
.error(
164-
"Newly registered logger with name `{}` and message factory `{}`, is requested to be associated with a different message factory: `{}`.\n"
165+
"Newly registered logger with name `{}` and message factory `{}`, is requested to be associated with a different name `{}` or message factory `{}`.\n"
165166
+ "Effectively the message factory of the logger will be used and the other one will be ignored.\n"
166167
+ "This generally hints a problem at the logger context implementation.\n"
167168
+ "Please report this using the Log4j project issue tracker.",
168-
name,
169+
loggerName,
169170
loggerMessageFactory,
171+
name,
170172
messageFactory);
173+
// Register logger under alternative keys
174+
loggerRefByNameByMessageFactory
175+
.computeIfAbsent(loggerMessageFactory, ignored -> new HashMap<>())
176+
.putIfAbsent(loggerName, new WeakReference<>(logger));
171177
}
172178

173179
// Insert the logger

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,9 @@
308308
<!-- project version -->
309309
<revision>2.25.0-SNAPSHOT</revision>
310310
<!-- Versions used on the site: no snapshots! -->
311-
<site-log4j-api.version>2.24.1</site-log4j-api.version>
312-
<site-log4j-core.version>2.24.1</site-log4j-core.version>
313-
<site-log4j-layout-template-json.version>2.24.1</site-log4j-layout-template-json.version>
311+
<site-log4j-api.version>2.24.2</site-log4j-api.version>
312+
<site-log4j-core.version>2.24.2</site-log4j-core.version>
313+
<site-log4j-layout-template-json.version>2.24.2</site-log4j-layout-template-json.version>
314314

315315
<!-- =================
316316
Common properties
@@ -324,7 +324,7 @@
324324
2. This value is employed in various places while creating the distribution
325325
To mitigate these, we define a *dummy* value here and let the CI replace it during a release.
326326
Hence, *DO NOT MANUALLY EDIT THIS VALUE*! -->
327-
<project.build.outputTimestamp>2024-09-24T13:33:09Z</project.build.outputTimestamp>
327+
<project.build.outputTimestamp>2024-11-18T20:27:38Z</project.build.outputTimestamp>
328328

329329
<!-- ========================
330330
Site-specific properties

src/changelog/2.24.1/.release-notes.adoc.ftl

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,21 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
////
17-
17+
<#-- @ftlvariable name="release.date" type="java.lang.String" -->
18+
<#-- @ftlvariable name="release.version" type="java.lang.String" -->
1819
[#release-notes-${release.version?replace("[^a-zA-Z0-9]", "-", "r")}]
1920
== ${release.version}
2021

2122
<#if release.date?has_content>Release date:: ${release.date}</#if>
2223

24+
[WARNING]
25+
====
26+
Due to a critical bug affecting this release (see
27+
https://github.com/apache/logging-log4j2/issues/3143[#3143])
28+
users are encouraged to upgrade to
29+
${'<<release-notes-2-24-2, version `2.24.2`>>'}.
30+
====
31+
2332
This release contains mainly bug fixes of problems encountered with the thread context map, logger registry and configuration reloading.
2433

2534
It also enhances integration tests to use Docker images of the most recent releases of MongoDB and Elastic Search.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
////
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
////
17+
<#-- @ftlvariable name="release.date" type="java.lang.String" -->
18+
<#-- @ftlvariable name="release.version" type="java.lang.String" -->
19+
[#release-notes-${release.version?replace("[^a-zA-Z0-9]", "-", "r")}]
20+
== ${release.version}
21+
22+
<#if release.date?has_content>Release date:: ${release.date}</#if>
23+
24+
This release fixes a critical bug in Log4j API initialization code, which can cause `LogManager.getLogger()` to return `null` under certain conditions.
25+
See
26+
https://github.com/apache/logging-log4j2/issues/3143[#3143]
27+
for details.
28+
29+
<#include "../.changelog.adoc.ftl">

src/changelog/2.24.2/.release.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<release xmlns="https://logging.apache.org/xml/ns"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
21+
date="2024-11-18" version="2.24.2"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="fixed">
6+
<issue id="3048" link="https://github.com/apache/logging-log4j2/pull/3048"/>
7+
<description format="asciidoc">Fix key removal issues in Thread Context</description>
8+
</entry>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="fixed">
6+
<issue id="3143" link="https://github.com/apache/logging-log4j2/issues/3143"/>
7+
<description format="asciidoc">
8+
Use hard references to ``Logger``s in `LoggerRegistry`.
9+
</description>
10+
</entry>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="fixed">
6+
<issue id="3216" link="https://github.com/apache/logging-log4j2/pull/3216"/>
7+
<description format="asciidoc">Fix `ArrayIndexOutOfBoundsException` in JSON Template Layout truncated exception resolver</description>
8+
</entry>

0 commit comments

Comments
 (0)