Skip to content

Commit dd9ec6b

Browse files
committed
Expose disruptor discard count in LoggerContext
1 parent 7b5d23e commit dd9ec6b

File tree

6 files changed

+38
-2
lines changed

6 files changed

+38
-2
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java

+11
Original file line numberDiff line numberDiff line change
@@ -802,4 +802,15 @@ private void initApiModule() {
802802
protected Logger newInstance(final LoggerContext ctx, final String name, final MessageFactory messageFactory) {
803803
return new Logger(ctx, name, messageFactory);
804804
}
805+
806+
/**
807+
* Returns the number of logging events discarded by the disruptor's queue full policy, or 0 if the disruptor
808+
* does not use a discarding policy or has not discarded. This is pulled from the disruptor used by this context's
809+
* associated {@link org.apache.logging.log4j.core.async.AsyncLoggerConfigDelegate}
810+
*
811+
* @return 0 if the disruptor is not configured to discard or has not discarded, otherwise a positive long
812+
*/
813+
public long getDiscardCount() {
814+
return configuration.getAsyncLoggerConfigDelegate().getDiscardCount();
815+
}
805816
}

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

+10
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ public interface AsyncLoggerConfigDelegate {
6262
* @param logEventFactory the factory used
6363
*/
6464
void setLogEventFactory(LogEventFactory logEventFactory);
65+
66+
/**
67+
* Returns the number of logging events discarded by the disruptor's queue full policy, or 0 if the disruptor
68+
* does not use a discarding policy or has not discarded.
69+
*
70+
* @return 0 if the disruptor is not configured to discard or has not discarded, otherwise a positive long
71+
*/
72+
default long getDiscardCount() {
73+
return 0;
74+
}
6575
}

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

+11
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,15 @@ public RingBufferAdmin createRingBufferAdmin() {
127127
public void setUseThreadLocals(final boolean useThreadLocals) {
128128
loggerDisruptor.setUseThreadLocals(useThreadLocals);
129129
}
130+
131+
/**
132+
* Returns the number of logging events discarded by the disruptor's queue full policy, or 0 if the disruptor
133+
* does not use a discarding policy or has not discarded.
134+
*
135+
* @return 0 if the disruptor is not configured to discard or has not discarded, otherwise a positive long
136+
*/
137+
@Override
138+
public long getDiscardCount() {
139+
return DiscardingAsyncQueueFullPolicy.getDiscardCount(loggerDisruptor.getAsyncQueueFullPolicy());
140+
}
130141
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ WaitStrategy getWaitStrategy() {
8686
return waitStrategy;
8787
}
8888

89+
AsyncQueueFullPolicy getAsyncQueueFullPolicy() {
90+
return asyncQueueFullPolicy;
91+
}
92+
8993
public String getContextName() {
9094
return contextName;
9195
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Provides Asynchronous Logger classes and interfaces for low-latency logging.
1919
*/
2020
@Export
21-
@Version("2.23.0")
21+
@Version("2.24.0")
2222
package org.apache.logging.log4j.core.async;
2323

2424
import org.osgi.annotation.bundle.Export;

log4j-core/src/main/java/org/apache/logging/log4j/core/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Implementation of Log4j 2.
1919
*/
2020
@Export
21-
@Version("2.20.2")
21+
@Version("2.21.0")
2222
package org.apache.logging.log4j.core;
2323

2424
import org.osgi.annotation.bundle.Export;

0 commit comments

Comments
 (0)