Skip to content

Commit 052f802

Browse files
committed
Raise default async discard threshold to ERROR
There are two basic scenarios where the ring buffer fills up. One is that an application is simply logging too much and the flushing process can't keep up, and in this case a discard threshold of WARN or INFO is probably sufficient to mitigate the problem. However, if flushing has stopped making progress altogether, e.g. due to a full or failed disk, then logging calls will block indefinitely. This can result in a production outage. This change sets the default discard threshold to ERROR, in order to better mitigate the scenario where the disk fills up, fails, or is in the process of failing. With this threshold, logging should only block at the FATAL level, which would typically mean that the operation is already failing anyway.
1 parent 2f79c39 commit 052f802

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void testCreateDiscardingRouterDefaultThresholdLevelInfo() {
7575
AsyncQueueFullPolicyFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
7676
AsyncQueueFullPolicyFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER);
7777
assertEquals(
78-
Level.INFO,
78+
Level.ERROR,
7979
((DiscardingAsyncQueueFullPolicy) AsyncQueueFullPolicyFactory.create()).getThresholdLevel());
8080
}
8181

@@ -85,7 +85,7 @@ void testCreateDiscardingRouterCaseInsensitive() {
8585
AsyncQueueFullPolicyFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER,
8686
toRootLowerCase(AsyncQueueFullPolicyFactory.PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER));
8787
assertEquals(
88-
Level.INFO,
88+
Level.ERROR,
8989
((DiscardingAsyncQueueFullPolicy) AsyncQueueFullPolicyFactory.create()).getThresholdLevel());
9090
}
9191

log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncQueueFullPolicyFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
* Property {@code "log4j2.AsyncQueueFullPolicy"} controls the routing behaviour. If this property is not specified or has
3131
* value {@code "Default"}, this factory creates {@link DefaultAsyncQueueFullPolicy} objects.
3232
* </p> <p>
33-
* If this property has value {@code "Discard"}, this factory creates {@link DiscardingAsyncQueueFullPolicy} objects.
34-
* By default, this router discards events of level {@code INFO}, {@code DEBUG} and {@code TRACE} if the queue is full.
35-
* This can be adjusted with property {@code "log4j2.DiscardThreshold"} (name of the level at which to start
36-
* discarding).
33+
* If this property has value {@code "Discard"}, this factory creates {@link DiscardingAsyncQueueFullPolicy} objects. By
34+
* default, this router discards events of level {@code ERROR}, {@code WARN}, {@code INFO}, {@code DEBUG} and {@code
35+
* TRACE} if the queue is full. This can be adjusted with property {@code "log4j2.DiscardThreshold"} (name of the level
36+
* at which to start discarding).
3737
* </p> <p>
3838
* For any other value, this
3939
* factory interprets the value as the fully qualified name of a class implementing the {@link AsyncQueueFullPolicy}
@@ -104,8 +104,8 @@ private static AsyncQueueFullPolicy createCustomRouter(final String router) {
104104

105105
private static AsyncQueueFullPolicy createDiscardingAsyncQueueFullPolicy() {
106106
final PropertiesUtil util = PropertiesUtil.getProperties();
107-
final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name());
108-
final Level thresholdLevel = Level.toLevel(level, Level.INFO);
107+
final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.ERROR.name());
108+
final Level thresholdLevel = Level.toLevel(level, Level.ERROR);
109109
LOGGER.debug("Creating custom DiscardingAsyncQueueFullPolicy(discardThreshold:{})", thresholdLevel);
110110
return new DiscardingAsyncQueueFullPolicy(thresholdLevel);
111111
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="3880" link="https://github.com/apache/logging-log4j2/pull/3880"/>
9+
<description format="asciidoc">
10+
Raise the async logger's default discard threshold to ERROR. This is intended to improve application resilience in the event of a full or failing disk.
11+
</description>
12+
</entry>

0 commit comments

Comments
 (0)