You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/03/22 12:55:31 UTC
[07/41] logging-log4j2 git commit: LOG4J2-1080 removed support for
dropping events on partially full queue,
removed support for property "log4j2.DiscardQueueRatio"
LOG4J2-1080 removed support for dropping events on partially full queue, removed support for property "log4j2.DiscardQueueRatio"
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6af9e31d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6af9e31d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6af9e31d
Branch: refs/heads/gelf-layout-gc-free
Commit: 6af9e31d117540ab57fa17b82967dbdff4e95868
Parents: f5a69e8
Author: rpopma <rp...@apache.org>
Authored: Tue Mar 15 01:56:55 2016 +1100
Committer: rpopma <rp...@apache.org>
Committed: Tue Mar 15 01:56:55 2016 +1100
----------------------------------------------------------------------
.../log4j/core/async/AsyncEventRouter.java | 7 +---
.../core/async/AsyncEventRouterFactory.java | 44 +++++++-------------
.../core/async/DefaultAsyncEventRouter.java | 5 +--
.../core/async/DiscardingAsyncEventRouter.java | 35 ++++------------
4 files changed, 26 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
index f2e709a..77ff5d7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouter.java
@@ -21,7 +21,7 @@ import org.apache.logging.log4j.Level;
/**
* Routing rule for deciding whether to log an event on the current thread, the background thread, or not at all.
*
- * @since 2.5.1
+ * @since 2.6
*/
public interface AsyncEventRouter {
@@ -30,10 +30,7 @@ public interface AsyncEventRouter {
*
* @param backgroundThreadId the thread ID of the background thread. Can be compared with the current thread's ID.
* @param level the level of the log event
- * @param queueSize total capacity of the queue used for asynchronous logging
- * @param queueRemainingCapacity remaining capacity of the queue
* @return the appropriate route for this routing rule
*/
- EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
- final int queueRemainingCapacity);
+ EventRoute getRoute(final long backgroundThreadId, final Level level);
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
index a1b254f..d4f0d8a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncEventRouterFactory.java
@@ -33,23 +33,21 @@ import org.apache.logging.log4j.util.PropertiesUtil;
* value {@code "Default"}, this factory creates {@link DefaultAsyncEventRouter} objects.
* </p> <p>
* If this property has value {@code "Discard"}, this factory creates {@link DiscardingAsyncEventRouter} objects.
- * By default, this router discards events of level {@code INFO}, {@code DEBUG} and {@code TRACE} if the queue is at
- * 80% capacity or more. This can be adjusted with properties {@code "log4j2.DiscardQueueRatio"} (must be a float
- * between 0.0 and 1.0) and {@code "log4j2.DiscardThreshold"} (name of the level at which to start discarding).
+ * By default, this router discards events of level {@code INFO}, {@code DEBUG} and {@code TRACE} if the queue is full.
+ * This can be adjusted with property {@code "log4j2.DiscardThreshold"} (name of the level at which to start
+ * discarding).
* </p> <p>
* For any other value, this
* factory interprets the value as the fully qualified name of a class implementing the {@link AsyncEventRouter}
- * interface. If a constructor with a single {@code int} argument exists, this constructor is invoked with the queue
- * size, otherwise the default constructor is called.
+ * interface. The class must have a default constructor.
* </p>
*
- * @since 2.5.1
+ * @since 2.6
*/
public class AsyncEventRouterFactory {
static final String PROPERTY_NAME_ASYNC_EVENT_ROUTER = "log4j2.AsyncEventRouter";
static final String PROPERTY_VALUE_DEFAULT_ASYNC_EVENT_ROUTER = "Default";
static final String PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER = "Discard";
- static final String PROPERTY_NAME_DISCARDING_QUEUE_RATIO = "log4j2.DiscardQueueRatio";
static final String PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL = "log4j2.DiscardThreshold";
private static final Logger LOGGER = StatusLogger.getLogger();
@@ -63,14 +61,12 @@ public class AsyncEventRouterFactory {
* If this property has value {@code "Discard"}, this method returns {@link DiscardingAsyncEventRouter} objects.
* </p> <p>
* For any other value, this method interprets the value as the fully qualified name of a class implementing the
- * {@link AsyncEventRouter} interface. If a constructor with a single {@code int} argument exists, this constructor
- * is invoked with the queue size, otherwise the default constructor is called.
+ * {@link AsyncEventRouter} interface. The class must have a default constructor.
* </p>
*
- * @param queueSize the queue size
* @return a new AsyncEventRouter
*/
- public static AsyncEventRouter create(final int queueSize) {
+ public static AsyncEventRouter create() {
final String router = PropertiesUtil.getProperties().getStringProperty(PROPERTY_NAME_ASYNC_EVENT_ROUTER);
if (router == null || PROPERTY_VALUE_DEFAULT_ASYNC_EVENT_ROUTER.equals(router)
|| DefaultAsyncEventRouter.class.getSimpleName().equals(router)
@@ -80,24 +76,16 @@ public class AsyncEventRouterFactory {
if (PROPERTY_VALUE_DISCARDING_ASYNC_EVENT_ROUTER.equals(router)
|| DiscardingAsyncEventRouter.class.getSimpleName().equals(router)
|| DiscardingAsyncEventRouter.class.getName().equals(router)) {
- return createDiscardingAsyncEventRouter(queueSize);
+ return createDiscardingAsyncEventRouter();
}
- return createCustomRouter(router, queueSize);
+ return createCustomRouter(router);
}
- private static AsyncEventRouter createCustomRouter(final String router, final int queueSize) {
+ private static AsyncEventRouter createCustomRouter(final String router) {
try {
final Class<? extends AsyncEventRouter> cls = LoaderUtil.loadClass(router).asSubclass(AsyncEventRouter.class);
- try {
- // if the custom router has a constructor taking an int, pass it the queue size
- Constructor<? extends AsyncEventRouter> constructor = cls.getDeclaredConstructor(new Class[]{int.class});
- LOGGER.debug("Creating custom AsyncEventRouter '{}({})'", router, queueSize);
- return constructor.newInstance(new Object[]{queueSize});
- } catch (final Exception e) {
- // otherwise we try the default constructor
- LOGGER.debug("Creating custom AsyncEventRouter '{}'", router);
- return cls.newInstance();
- }
+ LOGGER.debug("Creating custom AsyncEventRouter '{}'", router);
+ return cls.newInstance();
} catch (final Exception ex) {
LOGGER.debug("Using DefaultAsyncEventRouter. Could not create custom AsyncEventRouter '{}': {}", router,
ex.toString());
@@ -105,13 +93,11 @@ public class AsyncEventRouterFactory {
}
}
- private static AsyncEventRouter createDiscardingAsyncEventRouter(final int queueSize) {
+ private static AsyncEventRouter createDiscardingAsyncEventRouter() {
final PropertiesUtil util = PropertiesUtil.getProperties();
- final float ratio = (float) util.getDoubleProperty(PROPERTY_NAME_DISCARDING_QUEUE_RATIO, 0.8);
final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name());
final Level thresholdLevel = Level.toLevel(level, Level.INFO);
- LOGGER.debug("Creating custom DiscardingAsyncEventRouter(discardThreshold:{}, discardRatio:{})", thresholdLevel,
- ratio);
- return new DiscardingAsyncEventRouter(queueSize, ratio, thresholdLevel);
+ LOGGER.debug("Creating custom DiscardingAsyncEventRouter(discardThreshold:{})", thresholdLevel);
+ return new DiscardingAsyncEventRouter(thresholdLevel);
}
}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
index aee9336..122c4e8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncEventRouter.java
@@ -25,12 +25,11 @@ import org.apache.logging.log4j.Level;
*/
public class DefaultAsyncEventRouter implements AsyncEventRouter {
@Override
- public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
- final int queueRemainingCapacity) {
+ public EventRoute getRoute(final long backgroundThreadId, final Level level) {
// LOG4J2-471: prevent deadlock when RingBuffer is full and object
// being logged calls Logger.log() from its toString() method
- if (queueRemainingCapacity == 0 && Thread.currentThread().getId() == backgroundThreadId) {
+ if (Thread.currentThread().getId() == backgroundThreadId) {
return EventRoute.SYNCHRONOUS;
}
return EventRoute.ENQUEUE;
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6af9e31d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
index 2f5805a..8aa3f12 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DiscardingAsyncEventRouter.java
@@ -32,48 +32,31 @@ import java.util.concurrent.atomic.AtomicLong;
public class DiscardingAsyncEventRouter extends DefaultAsyncEventRouter {
private static final Logger LOGGER = StatusLogger.getLogger();
- private final int thresholdQueueRemainingCapacity;
private final Level thresholdLevel;
private final AtomicLong discardCount = new AtomicLong();
/**
* Constructs a router that will discard events {@linkplain Level#isLessSpecificThan(Level) equal or less specific}
- * than the specified threshold level when the queue is fuller than the specified threshold ratio.
+ * than the specified threshold level when the queue is full.
*
- * @param queueSize size of the queue
- * @param thresholdQueueFilledRatio threshold ratio: if queue is fuller than this, start discarding events
* @param thresholdLevel level of events to discard
*/
- public DiscardingAsyncEventRouter(final int queueSize, final float thresholdQueueFilledRatio,
- final Level thresholdLevel) {
- thresholdQueueRemainingCapacity = calcThresholdQueueRemainingCapacity(queueSize, thresholdQueueFilledRatio);
+ public DiscardingAsyncEventRouter(final Level thresholdLevel) {
this.thresholdLevel = Objects.requireNonNull(thresholdLevel, "thresholdLevel");
}
- private static int calcThresholdQueueRemainingCapacity(final int queueSize,
- final float thresholdQueueFilledRatio) {
- if (thresholdQueueFilledRatio >= 1F) {
- return 0;
- }
- if (thresholdQueueFilledRatio <= 0F) {
- return queueSize;
- }
- return (int) ((1 - thresholdQueueFilledRatio) * queueSize);
- }
-
@Override
- public EventRoute getRoute(final long backgroundThreadId, final Level level, final int queueSize,
- final int queueRemainingCapacity) {
- if (queueRemainingCapacity <= thresholdQueueRemainingCapacity && level.isLessSpecificThan(thresholdLevel)) {
+ public EventRoute getRoute(final long backgroundThreadId, final Level level) {
+ if (level.isLessSpecificThan(thresholdLevel)) {
if (discardCount.getAndIncrement() == 0) {
- LOGGER.warn("Async remaining queue capacity is {}, discarding event with level {}. " +
+ LOGGER.warn("Async queue is full, discarding event with level {}. " +
"This message will only appear once; future events from {} " +
"are silently discarded until queue capacity becomes available.",
- queueRemainingCapacity, level, thresholdLevel);
+ level, thresholdLevel);
}
return EventRoute.DISCARD;
}
- return super.getRoute(backgroundThreadId, level, queueSize, queueRemainingCapacity);
+ return super.getRoute(backgroundThreadId, level);
}
public static long getDiscardCount(final AsyncEventRouter router) {
@@ -83,10 +66,6 @@ public class DiscardingAsyncEventRouter extends DefaultAsyncEventRouter {
return 0;
}
- public int getThresholdQueueRemainingCapacity() {
- return thresholdQueueRemainingCapacity;
- }
-
public Level getThresholdLevel() {
return thresholdLevel;
}