You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/16 07:30:56 UTC
logging-log4j2 git commit: LOG4J2-1334 simplify AsyncAppender: now
that any LogEvent can be serialized there is no more need to downcast to
Log4jLogEvent or copy a RingBufferLogEvent into a Log4jLogEvent
Repository: logging-log4j2
Updated Branches:
refs/heads/master 412d7947d -> 08228f2da
LOG4J2-1334 simplify AsyncAppender: now that any LogEvent can be serialized there is no more need to downcast to Log4jLogEvent or copy a RingBufferLogEvent into a Log4jLogEvent
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/08228f2d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/08228f2d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/08228f2d
Branch: refs/heads/master
Commit: 08228f2da38ae1afac22e0681dff3a5a1d944a4c
Parents: 412d794
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 14:30:56 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 14:30:56 2016 +0900
----------------------------------------------------------------------
.../log4j/core/appender/AsyncAppender.java | 28 +++++---------------
.../logging/log4j/core/async/EventRoute.java | 9 +++----
2 files changed, 11 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/08228f2d/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
index 31bdfbf..aa10155 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
@@ -24,7 +24,6 @@ import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.atomic.AtomicLong;
-import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
@@ -32,7 +31,6 @@ import org.apache.logging.log4j.core.async.AsyncEventRouter;
import org.apache.logging.log4j.core.async.AsyncEventRouterFactory;
import org.apache.logging.log4j.core.async.DiscardingAsyncEventRouter;
import org.apache.logging.log4j.core.async.EventRoute;
-import org.apache.logging.log4j.core.async.RingBufferLogEvent;
import org.apache.logging.log4j.core.config.AppenderControl;
import org.apache.logging.log4j.core.config.AppenderRef;
import org.apache.logging.log4j.core.config.Configuration;
@@ -145,22 +143,10 @@ public final class AsyncAppender extends AbstractAppender {
if (!isStarted()) {
throw new IllegalStateException("AsyncAppender " + getName() + " is not active");
}
- if (!(logEvent instanceof Log4jLogEvent)) {
- if (!(logEvent instanceof RingBufferLogEvent)) {
- return; // only know how to Serialize Log4jLogEvents and RingBufferLogEvents
- }
- logEvent = ((RingBufferLogEvent) logEvent).createMemento();
- }
if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND) { // LOG4J2-898: user may choose
logEvent.getMessage().getFormattedMessage(); // LOG4J2-763: ask message to freeze parameters
}
- final Log4jLogEvent coreEvent = (Log4jLogEvent) logEvent;
- logEvent(coreEvent);
- }
-
- private void logEvent(final Log4jLogEvent logEvent) {
- final Level logLevel = logEvent.getLevel();
- final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logLevel);
+ final EventRoute route = asyncEventRouter.getRoute(thread.getId(), logEvent.getLevel());
route.logMessage(this, logEvent);
}
@@ -169,7 +155,7 @@ public final class AsyncAppender extends AbstractAppender {
*
* @param logEvent the event to log
*/
- public void logMessageInCurrentThread(final Log4jLogEvent logEvent) {
+ public void logMessageInCurrentThread(final LogEvent logEvent) {
logEvent.setEndOfBatch(queue.isEmpty());
final boolean appendSuccessful = thread.callAppenders(logEvent);
logToErrorAppenderIfNecessary(appendSuccessful, logEvent);
@@ -180,12 +166,12 @@ public final class AsyncAppender extends AbstractAppender {
*
* @param logEvent the event to log
*/
- public void logMessageInBackgroundThread(final Log4jLogEvent logEvent) {
+ public void logMessageInBackgroundThread(final LogEvent logEvent) {
final boolean success = blocking ? enqueueOrBlockIfQueueFull(logEvent) : enqueueOrDropIfQueueFull(logEvent);
logToErrorAppenderIfNecessary(success, logEvent);
}
- private boolean enqueueOrBlockIfQueueFull(final Log4jLogEvent logEvent) {
+ private boolean enqueueOrBlockIfQueueFull(final LogEvent logEvent) {
boolean appendSuccessful;
final Serializable serialized = Log4jLogEvent.serialize(logEvent, includeLocation);
try {
@@ -198,7 +184,7 @@ public final class AsyncAppender extends AbstractAppender {
return appendSuccessful;
}
- private boolean enqueueOrDropIfQueueFull(final Log4jLogEvent logEvent) {
+ private boolean enqueueOrDropIfQueueFull(final LogEvent logEvent) {
final boolean appendSuccessful = queue.offer(Log4jLogEvent.serialize(logEvent, includeLocation));
if (!appendSuccessful) {
error("Appender " + getName() + " is unable to write primary appenders. queue is full");
@@ -228,7 +214,7 @@ public final class AsyncAppender extends AbstractAppender {
return appendSuccessful;
}
- private void logToErrorAppenderIfNecessary(final boolean appendSuccessful, final Log4jLogEvent logEvent) {
+ private void logToErrorAppenderIfNecessary(final boolean appendSuccessful, final LogEvent logEvent) {
if (!appendSuccessful && errorAppender != null) {
errorAppender.callAppender(logEvent);
}
@@ -350,7 +336,7 @@ public final class AsyncAppender extends AbstractAppender {
* @param event the event to forward to the registered appenders
* @return {@code true} if at least one appender call succeeded, {@code false} otherwise
*/
- boolean callAppenders(final Log4jLogEvent event) {
+ boolean callAppenders(final LogEvent event) {
boolean success = false;
for (final AppenderControl control : appenders) {
try {
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/08228f2d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
index ce57008..2558010 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java
@@ -20,7 +20,6 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AsyncAppender;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.message.Message;
/**
@@ -44,7 +43,7 @@ public enum EventRoute {
}
@Override
- public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent logEvent) {
+ public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
asyncAppender.logMessageInBackgroundThread(logEvent);
}
},
@@ -63,7 +62,7 @@ public enum EventRoute {
}
@Override
- public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent logEvent) {
+ public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) {
asyncAppender.logMessageInCurrentThread(logEvent);
}
},
@@ -83,7 +82,7 @@ public enum EventRoute {
}
@Override
- public void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent coreEvent) {
+ public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) {
// do nothing: drop the event
}
};
@@ -93,5 +92,5 @@ public enum EventRoute {
public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event);
- public abstract void logMessage(final AsyncAppender asyncAppender, final Log4jLogEvent coreEvent);
+ public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent);
}