diff --git a/log4j-async-logger/pom.xml b/log4j-async-logger/pom.xml
new file mode 100644
index 00000000000..aba22bd83d9
--- /dev/null
+++ b/log4j-async-logger/pom.xml
@@ -0,0 +1,86 @@
+
+
+
+ 4.0.0
+
+ org.apache.logging.log4j
+ log4j
+ ${revision}
+ ../log4j-parent
+
+
+ log4j-async-logger
+ Apache Log4j Async Logger
+ Alternative implementation of logger that uses LMAX Disruptor.
+
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+
+
+
+ com.lmax
+ disruptor
+
+
+
+ org.apache.logging.log4j
+ log4j-core-test
+ test
+
+
+
+ org.awaitility
+ awaitility
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+
+ org.mockito
+ mockito-core
+ test
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+
+ org.apache.logging.log4j
+ log4j-plugin-processor
+ ${project.version}
+
+
+
+
+
+
+
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AbstractAsyncExceptionHandler.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AbstractAsyncExceptionHandler.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AbstractAsyncExceptionHandler.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AbstractAsyncExceptionHandler.java
index dd84b23c528..51f1c7bc962 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AbstractAsyncExceptionHandler.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AbstractAsyncExceptionHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.ExceptionHandler;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLogger.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLogger.java
index 5515fcbb348..ef58ea767ce 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLogger.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.util.List;
import org.apache.logging.log4j.Level;
@@ -24,6 +24,8 @@
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.ReusableLogEvent;
+import org.apache.logging.log4j.core.async.AsyncQueueFullMessageUtil;
+import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Property;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig.java
similarity index 89%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig.java
index 83295de6350..da36cf561aa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig.java
@@ -14,14 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.async.AsyncQueueFullMessageUtil;
+import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.core.config.AppenderRef;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
@@ -79,6 +82,7 @@ public LoggerConfig build() {
final String name = getLoggerName().equals(ROOT) ? Strings.EMPTY : getLoggerName();
final LevelAndRefs container =
LoggerConfig.getLevelAndRefs(getLevel(), getRefs(), getLevelAndRefs(), getConfig());
+ final String includeLocationConfigValue = getIncludeLocation();
return new AsyncLoggerConfig(
name,
container.refs,
@@ -87,7 +91,7 @@ public LoggerConfig build() {
isAdditivity(),
getProperties(),
getConfig(),
- includeLocation(getIncludeLocation()),
+ Boolean.parseBoolean(includeLocationConfigValue),
getLogEventFactory());
}
}
@@ -116,9 +120,9 @@ public void initialize() {
super.initialize();
}
- protected void log(final LogEvent event, final LoggerConfigPredicate predicate) {
+ protected void log(final LogEvent event, final Predicate predicate) {
// See LOG4J2-2301
- if (predicate == LoggerConfigPredicate.ALL
+ if (predicate == null
&& ASYNC_LOGGER_ENTERED.get() == Boolean.FALSE
&&
// Optimization: AsyncLoggerConfig is identical to LoggerConfig
@@ -132,7 +136,7 @@ protected void log(final LogEvent event, final LoggerConfigPredicate predicate)
if (!isFiltered(event)) {
// Detect the first time we encounter an AsyncLoggerConfig. We must log
// to all non-async loggers first.
- processLogEvent(event, LoggerConfigPredicate.SYNCHRONOUS_ONLY);
+ processLogEvent(event, lc -> !(lc instanceof AsyncLoggerConfig));
// Then pass the event to the background thread where
// all async logging is executed. It is important this
// happens at most once and after all synchronous loggers
@@ -175,7 +179,17 @@ private void handleQueueFull(final LogEvent event) {
} else {
// otherwise, we leave it to the user preference
final EventRoute eventRoute = delegate.getEventRoute(event.getLevel());
- eventRoute.logMessage(this, event);
+ switch (eventRoute) {
+ case DISCARD:
+ break;
+ case ENQUEUE:
+ logInBackgroundThread(event);
+ break;
+ case SYNCHRONOUS:
+ logToAsyncLoggerConfigsOnCurrentThread(event);
+ break;
+ default:
+ }
}
}
@@ -196,7 +210,7 @@ void logInBackgroundThread(final LogEvent event) {
*/
void logToAsyncLoggerConfigsOnCurrentThread(final LogEvent event) {
// skip the filter, which was already called on the logging thread
- processLogEvent(event, LoggerConfigPredicate.ASYNCHRONOUS_ONLY);
+ processLogEvent(event, lc -> lc instanceof AsyncLoggerConfig);
}
private String displayName() {
@@ -218,11 +232,6 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) {
return true;
}
- // Note: for asynchronous loggers, includeLocation default is FALSE
- protected static boolean includeLocation(final String includeLocationConfigValue) {
- return Boolean.parseBoolean(includeLocationConfigValue);
- }
-
/**
* An asynchronous root Logger.
*/
@@ -241,6 +250,7 @@ public static class Builder> extends RootLogger.Builder
public LoggerConfig build() {
final LevelAndRefs container =
LoggerConfig.getLevelAndRefs(getLevel(), getRefs(), getLevelAndRefs(), getConfig());
+ final String includeLocationConfigValue = getIncludeLocation();
return new AsyncLoggerConfig(
LogManager.ROOT_LOGGER_NAME,
container.refs,
@@ -249,7 +259,7 @@ public LoggerConfig build() {
isAdditivity(),
getProperties(),
getConfig(),
- AsyncLoggerConfig.includeLocation(getIncludeLocation()),
+ Boolean.parseBoolean(includeLocationConfigValue),
getLogEventFactory());
}
}
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDefaultExceptionHandler.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDefaultExceptionHandler.java
similarity index 95%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDefaultExceptionHandler.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDefaultExceptionHandler.java
index 1bf13f7dd3d..3502bb38d0e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDefaultExceptionHandler.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDefaultExceptionHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
/**
* Default disruptor exception handler for errors that occur in the AsyncLogger background thread.
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDelegate.java
similarity index 95%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDelegate.java
index e2145a93f49..e3997404c42 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDelegate.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDelegate.java
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.core.impl.LogEventFactory;
/**
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDisruptor.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDisruptor.java
index 3f27efc83fb..b132e6ae847 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigDisruptor.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigDisruptor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.EventFactory;
import com.lmax.disruptor.EventHandler;
@@ -34,6 +34,11 @@
import org.apache.logging.log4j.core.AbstractLifeCycle;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.ReusableLogEvent;
+import org.apache.logging.log4j.core.async.AsyncQueueFullPolicy;
+import org.apache.logging.log4j.core.async.AsyncQueueFullPolicyFactory;
+import org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy;
+import org.apache.logging.log4j.core.async.EventRoute;
+import org.apache.logging.log4j.core.async.InternalAsyncUtil;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.impl.LogEventFactory;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContext.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContext.java
similarity index 97%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContext.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContext.java
index 12cd555b7f5..8e1ce4290e4 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContext.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContext.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.net.URI;
import java.util.concurrent.TimeUnit;
@@ -130,6 +130,11 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) {
return true;
}
+ @Override
+ public boolean includeLocation() {
+ return false;
+ }
+
// package-protected for tests
AsyncLoggerDisruptor getAsyncLoggerDisruptor() {
return loggerDisruptor;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelector.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelector.java
similarity index 75%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelector.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelector.java
index bc41ee487c0..31e5b9c4031 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelector.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelector.java
@@ -14,16 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.net.URI;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.selector.ClassLoaderContextSelector;
import org.apache.logging.log4j.plugins.Inject;
import org.apache.logging.log4j.plugins.Singleton;
import org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory;
-import org.apache.logging.log4j.util.PropertiesUtil;
/**
* {@code ContextSelector} that manages {@code AsyncLoggerContext} instances.
@@ -33,19 +31,6 @@
@Singleton
public class AsyncLoggerContextSelector extends ClassLoaderContextSelector {
- /**
- * Returns {@code true} if the user specified this selector as the Log4jContextSelector, to make all loggers
- * asynchronous.
- *
- * @return {@code true} if all loggers are asynchronous, {@code false} otherwise.
- */
- public static boolean isSelected() {
- // FIXME(ms): this should check Injector bindings
- return AsyncLoggerContextSelector.class
- .getName()
- .equals(PropertiesUtil.getProperties().getStringProperty(Log4jPropertyKey.CONTEXT_SELECTOR_CLASS_NAME));
- }
-
@Inject
public AsyncLoggerContextSelector(final ConfigurableInstanceFactory instanceFactory) {
super(instanceFactory);
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultExceptionHandler.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultExceptionHandler.java
similarity index 95%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultExceptionHandler.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultExceptionHandler.java
index 058d306c223..f8e866183fe 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultExceptionHandler.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultExceptionHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
/**
* Default disruptor exception handler for errors that occur in the AsyncLogger background thread.
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDisruptor.java
similarity index 97%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDisruptor.java
index b3281e42168..b2280e62b7e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncLoggerDisruptor.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.ExceptionHandler;
import com.lmax.disruptor.RingBuffer;
@@ -30,6 +30,10 @@
import java.util.function.Supplier;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.AbstractLifeCycle;
+import org.apache.logging.log4j.core.async.AsyncQueueFullPolicy;
+import org.apache.logging.log4j.core.async.AsyncQueueFullPolicyFactory;
+import org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy;
+import org.apache.logging.log4j.core.async.EventRoute;
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.util.Log4jThread;
import org.apache.logging.log4j.core.util.Log4jThreadFactory;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactory.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncWaitStrategyFactory.java
similarity index 96%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactory.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncWaitStrategyFactory.java
index 7b5f1c0b1a6..491b37eebf7 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncWaitStrategyFactory.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/AsyncWaitStrategyFactory.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.WaitStrategy;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelector.java
similarity index 97%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelector.java
index 7292941cd54..e8d458f4662 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelector.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelector.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.net.URI;
import org.apache.logging.log4j.core.LoggerContext;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncWaitStrategyFactory.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DefaultAsyncWaitStrategyFactory.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncWaitStrategyFactory.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DefaultAsyncWaitStrategyFactory.java
index 1014846a660..d0084a17ee3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DefaultAsyncWaitStrategyFactory.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DefaultAsyncWaitStrategyFactory.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.BusySpinWaitStrategy;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorConfiguration.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorConfiguration.java
similarity index 99%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorConfiguration.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorConfiguration.java
index 035aa4c445d..01eccd43e64 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorConfiguration.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorConfiguration.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorUtil.java
similarity index 99%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorUtil.java
index 7d9444e0ef1..9716276ed65 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/DisruptorUtil.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/DisruptorUtil.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.apache.logging.log4j.core.impl.Log4jPropertyKey.ASYNC_CONFIG_EXCEPTION_HANDLER_CLASS_NAME;
import static org.apache.logging.log4j.core.impl.Log4jPropertyKey.ASYNC_LOGGER_EXCEPTION_HANDLER_CLASS_NAME;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEvent.java
similarity index 99%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEvent.java
index 5d97613bc2f..4c4b6da4c2d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEvent.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.EventFactory;
import java.util.Arrays;
@@ -23,6 +23,7 @@
import org.apache.logging.log4j.ThreadContext.ContextStack;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.ReusableLogEvent;
+import org.apache.logging.log4j.core.async.InternalAsyncUtil;
import org.apache.logging.log4j.core.impl.ContextDataFactory;
import org.apache.logging.log4j.core.impl.Log4jLogEvent;
import org.apache.logging.log4j.core.impl.MementoMessage;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventHandler.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventHandler.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventHandler.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventHandler.java
index f141846591f..f19be654937 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventHandler.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventHandler.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.Sequence;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTranslator.java
similarity index 99%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTranslator.java
index 15b2b652bcb..96948902be0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEventTranslator.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTranslator.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.EventTranslator;
import org.apache.logging.log4j.Level;
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/TimeoutBlockingWaitStrategy.java b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/TimeoutBlockingWaitStrategy.java
similarity index 98%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/async/TimeoutBlockingWaitStrategy.java
rename to log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/TimeoutBlockingWaitStrategy.java
index 77db1635c9e..657da6fec47 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/TimeoutBlockingWaitStrategy.java
+++ b/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/TimeoutBlockingWaitStrategy.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import com.lmax.disruptor.AlertException;
import com.lmax.disruptor.BatchEventProcessor;
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLateConfigTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLateConfigTest.java
new file mode 100644
index 00000000000..79cf78d7ecd
--- /dev/null
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLateConfigTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.async.logger;
+
+import java.nio.file.Path;
+import java.util.stream.Stream;
+import org.apache.logging.log4j.core.impl.Log4jContextFactory;
+import org.apache.logging.log4j.core.selector.ContextSelector;
+import org.apache.logging.log4j.core.test.LateConfigAbstractTest;
+import org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory;
+import org.apache.logging.log4j.plugins.di.DI;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+@Tag("functional")
+@UsingStatusListener
+public class AsyncLateConfigTest extends LateConfigAbstractTest {
+
+ @TempLoggingDir
+ private static Path loggingPath;
+
+ static Stream selectors() {
+ final ConfigurableInstanceFactory instanceFactory = DI.createInitializedFactory();
+ return Stream.of(
+ new AsyncLoggerContextSelector(instanceFactory.newChildInstanceFactory()),
+ new BasicAsyncLoggerContextSelector(instanceFactory.newChildInstanceFactory()))
+ .map(Log4jContextFactory::new);
+ }
+
+ @ParameterizedTest(name = "reconfigure {0}")
+ @MethodSource("selectors")
+ void reconfiguration(final Log4jContextFactory factory) throws Exception {
+ testReconfiguration(factory, loggingPath);
+ }
+}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlockTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerClassLoadDeadlockTest.java
similarity index 58%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlockTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerClassLoadDeadlockTest.java
index c015520406e..b4ff970790c 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlockTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerClassLoadDeadlockTest.java
@@ -14,25 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.test.junit.SetTestProperty;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
-import org.junitpioneer.jupiter.SetSystemProperty;
/**
* Test class loading deadlock condition from the LOG4J2-1457
*/
@Tag("async")
-@SetSystemProperty(
- key = Log4jPropertyKey.Constant.CONTEXT_SELECTOR_CLASS_NAME,
+@SetTestProperty(
+ key = "LoggerContext.selector",
value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.ASYNC_LOGGER_RING_BUFFER_SIZE, value = "128")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerConsoleTest.xml")
+@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
+@SetTestProperty(
+ key = "Configuration.file",
+ value = "org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlockTest.xml")
public class AsyncLoggerClassLoadDeadlockTest {
static final int RING_BUFFER_SIZE = 128;
@@ -41,7 +44,19 @@ public class AsyncLoggerClassLoadDeadlockTest {
@Timeout(value = 30)
public void testClassLoaderDeadlock() throws Exception {
// touch the class so static init will be called
- final AsyncLoggerClassLoadDeadlock temp = new AsyncLoggerClassLoadDeadlock();
+ final DeadLock temp = new DeadLock();
assertNotNull(temp);
}
+
+ static final class DeadLock {
+ static {
+ final Logger log = LogManager.getLogger("com.foo.bar.deadlock");
+ final Exception e = new Exception();
+ // the key to reproducing the problem is to fill up the ring buffer so that
+ // log.info call will block on ring buffer as well
+ for (int i = 0; i < AsyncLoggerClassLoadDeadlockTest.RING_BUFFER_SIZE * 2; ++i) {
+ log.info("clinit", e);
+ }
+ }
+ }
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest2.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.java
similarity index 68%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest2.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.java
index 3c92d26b1d6..ff45f7b9045 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest2.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -22,35 +22,37 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import org.apache.logging.log4j.LogManager;
+import java.nio.file.Path;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerConfigTest2.xml")
-public class AsyncLoggerConfigTest2 {
+@UsingStatusListener
+public class AsyncLoggerConfig2Test {
+
+ @TempLoggingDir
+ private static Path loggingPath;
@Test
- public void testConsecutiveReconfigure() throws Exception {
- final File file = new File("target", "AsyncLoggerConfigTest2.log");
- assertTrue(!file.exists() || file.delete(), "Deleted old file before test");
+ @LoggerContextSource
+ public void testConsecutiveReconfigure(final LoggerContext ctx) throws Exception {
+ final File file = loggingPath.resolve("AsyncLoggerConfigTest2.log").toFile();
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ final Logger log = ctx.getLogger("com.foo.Bar");
final String msg = "Message before reconfig";
log.info(msg);
- final LoggerContext ctx = LoggerContext.getContext(false);
ctx.reconfigure();
ctx.reconfigure();
final String msg2 = "Message after reconfig";
log.info(msg2);
- CoreLoggerContexts.stopLoggerContext(file); // stop async thread
+ ctx.stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.java
similarity index 90%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.java
index 39b26a518c1..8508971b990 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest3.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.java
@@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
+import java.nio.file.Path;
import java.util.HashMap;
import java.util.Map;
import org.apache.logging.log4j.Level;
@@ -24,17 +25,19 @@
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.ParameterizedMessage;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag("async")
@Tag("sleepy")
-public class AsyncLoggerConfigTest3 {
+public class AsyncLoggerConfig3Test {
+
+ @TempLoggingDir
+ private static Path loggingPath;
@Test
- @CleanUpFiles("target/AsyncLoggerConfigTest2.log")
- @LoggerContextSource("AsyncLoggerConfigTest2.xml")
+ @LoggerContextSource
public void testNoConcurrentModificationException(final Logger log) throws Exception {
log.info("initial message");
Thread.sleep(500);
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig4Test.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig4Test.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig4Test.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig4Test.java
index f95ddedbf05..5f203739be1 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfig4Test.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfig4Test.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigAutoFlushTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.java
similarity index 60%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigAutoFlushTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.java
index b022853d640..d59738208a2 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigAutoFlushTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.java
@@ -14,35 +14,36 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.nio.file.Files;
-import org.apache.logging.log4j.LogManager;
+import java.nio.file.Path;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerConfigAutoFlushTest.xml")
public class AsyncLoggerConfigAutoFlushTest {
+ @TempLoggingDir
+ private static Path loggingPath;
+
@Test
- @CleanUpFiles("target/AsyncLoggerConfigAutoFlushTest.log")
- public void testFlushAtEndOfBatch() throws Exception {
- final File file = new File("target", "AsyncLoggerConfigAutoFlushTest.log");
- assertTrue(!file.exists() || file.delete(), "Deleted old file before test");
+ @LoggerContextSource
+ public void testFlushAtEndOfBatch(final LoggerContext ctx) throws Exception {
+ final File file =
+ loggingPath.resolve("AsyncLoggerConfigAutoFlushTest.log").toFile();
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ final Logger log = ctx.getLogger("com.foo.Bar");
final String msg = "Message flushed with immediate flush=false";
log.info(msg);
- CoreLoggerContexts.stopLoggerContext(file); // stop async thread
+ ctx.stop(); // stop async thread
final String contents = Files.readString(file.toPath());
assertTrue(contents.contains(msg), "line1 correct");
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigErrorOnFormat.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.java
similarity index 88%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigErrorOnFormat.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.java
index fbfec402d09..7ed1bfe672f 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigErrorOnFormat.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@@ -23,29 +23,34 @@
import java.io.File;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.AsynchronouslyFormattable;
import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerConfigErrorOnFormat.xml")
@SetSystemProperty(
key = Log4jPropertyKey.Constant.LOG_EVENT_FACTORY_CLASS_NAME,
value = "org.apache.logging.log4j.core.impl.DefaultLogEventFactory")
public class AsyncLoggerConfigErrorOnFormat {
+ @TempLoggingDir
+ private static Path loggingPath;
+
@Test
- @CleanUpFiles("target/AsyncLoggerConfigErrorOnFormat.log")
+ @LoggerContextSource
public void testError() throws Exception {
- final File file = new File("target", "AsyncLoggerConfigErrorOnFormat.log");
+ final File file =
+ loggingPath.resolve("AsyncLoggerConfigErrorOnFormat.log").toFile();
assertTrue(!file.exists() || file.delete(), "Deleted old file before test");
final Logger log = LogManager.getLogger("com.foo.Bar");
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigTest.java
similarity index 97%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigTest.java
index 3dba066194f..6a08fdaf867 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -30,10 +30,10 @@
import java.nio.file.Path;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.async.logger.AsyncLoggerConfig.RootLogger;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.async.AsyncLoggerConfig.RootLogger;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.NullConfiguration;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigUseAfterShutdownTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.java
similarity index 63%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigUseAfterShutdownTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.java
index 9a3877b1af9..79165e5c9bd 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigUseAfterShutdownTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.java
@@ -14,31 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
+import java.nio.file.Path;
import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerConfigTest.xml")
public class AsyncLoggerConfigUseAfterShutdownTest {
+ @TempLoggingDir
+ private static Path loggingPath;
+
@Test
- public void testNoErrorIfLogAfterShutdown() throws Exception {
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ @LoggerContextSource
+ public void testNoErrorIfLogAfterShutdown(final LoggerContext ctx) throws Exception {
+ final Logger log = ctx.getLogger("com.foo.Bar");
log.info("some message");
- CoreLoggerContexts.stopLoggerContext(); // stop async thread
+ ctx.stop(); // stop async thread
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
- ((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
+ log.logMessage(Level.INFO, null, "com.foo.Bar", null, new SimpleMessage("msg"), null);
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigWithAsyncEnabledTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigWithAsyncEnabledTest.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigWithAsyncEnabledTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigWithAsyncEnabledTest.java
index 3cbcdaf5f34..657cc65bee5 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerConfigWithAsyncEnabledTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerConfigWithAsyncEnabledTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorInitialStateTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorInitialStateTest.java
similarity index 96%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorInitialStateTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorInitialStateTest.java
index 8e3af122358..31997d697b4 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorInitialStateTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorInitialStateTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorTest.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorTest.java
index 7c6081e7c0a..b3141cb42b8 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextSelectorTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextSelectorTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextTest.java
similarity index 96%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextTest.java
index 54403bbd9e2..a89108b3c0b 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerContextTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerContextTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.Assert.assertTrue;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerCustomSelectorLocationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.java
similarity index 74%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerCustomSelectorLocationTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.java
index 5b274ab26fb..f84dd735abe 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerCustomSelectorLocationTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
@@ -25,47 +25,37 @@
import java.io.File;
import java.io.FileReader;
import java.net.URI;
+import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.selector.ContextSelector;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.plugins.Singleton;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag("async")
@ContextSelectorType(AsyncLoggerCustomSelectorLocationTest.CustomAsyncContextSelector.class)
-@CleanUpFiles("target/AsyncLoggerCustomSelectorLocationTest.log")
public class AsyncLoggerCustomSelectorLocationTest {
- @BeforeEach
- public void beforeEach() throws Exception {
- System.setProperty(
- Log4jPropertyKey.CONFIG_LOCATION.getSystemKey(), "AsyncLoggerCustomSelectorLocationTest.xml");
- }
-
- @AfterEach
- public void afterEach() throws Exception {
- System.clearProperty(Log4jPropertyKey.CONFIG_LOCATION.getSystemKey());
- }
+ @TempLoggingDir
+ private static Path loggingPath;
@Test
- public void testCustomAsyncSelectorLocation() throws Exception {
- final File file = new File("target", "AsyncLoggerCustomSelectorLocationTest.log");
- final Logger log = LogManager.getLogger("com.foo.Bar");
- final Logger logIncludingLocation = LogManager.getLogger("com.include.location.Bar");
+ @LoggerContextSource
+ public void testCustomAsyncSelectorLocation(final LoggerContext ctx) throws Exception {
+ final File file =
+ loggingPath.resolve("AsyncLoggerCustomSelectorLocationTest.log").toFile();
+ final Logger log = ctx.getLogger("com.foo.Bar");
+ final Logger logIncludingLocation = ctx.getLogger("com.include.location.Bar");
final String msg = "Async logger msg with location";
log.info(msg);
logIncludingLocation.info(msg);
- CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
+ ctx.stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String firstLine = reader.readLine();
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultLocationTest.java
similarity index 80%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultLocationTest.java
index 33cca5ff641..6c2e5b3bbb3 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerDefaultLocationTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultLocationTest.java
@@ -14,29 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerDefaultLocationTest.xml")
public class AsyncLoggerDefaultLocationTest {
@Test
- public void testAsyncLogWritesToLog() throws Exception {
- final LoggerContext context = (LoggerContext) LogManager.getContext(false);
+ @LoggerContextSource
+ public void testAsyncLogWritesToLog(final LoggerContext context) throws Exception {
final ListAppender app = context.getConfiguration().getAppender("List");
assertNotNull(app);
final Logger log = context.getLogger("com.foo.Bar");
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerEventTranslationExceptionTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
similarity index 89%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerEventTranslationExceptionTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
index ffbe9238f9e..a5a32b29f1a 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerEventTranslationExceptionTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -23,11 +23,11 @@
import com.lmax.disruptor.ExceptionHandler;
import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.message.ReusableSimpleMessage;
import org.apache.logging.log4j.spi.AbstractLogger;
@@ -44,16 +44,16 @@
*/
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "log4j2-console.xml")
@SetSystemProperty(
key = Log4jPropertyKey.Constant.ASYNC_LOGGER_EXCEPTION_HANDLER_CLASS_NAME,
- value = "org.apache.logging.log4j.core.async.AsyncLoggerEventTranslationExceptionTest$TestExceptionHandler")
+ value = "org.apache.logging.log4j.async.logger.AsyncLoggerEventTranslationExceptionTest$TestExceptionHandler")
class AsyncLoggerEventTranslationExceptionTest {
@Test
- void testEventTranslationExceptionDoesNotCauseAsyncEventException() {
+ @LoggerContextSource
+ void testEventTranslationExceptionDoesNotCauseAsyncEventException(final LoggerContext ctx) {
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ final Logger log = ctx.getLogger("com.foo.Bar");
assertTrue(TestExceptionHandler.INSTANTIATED, "TestExceptionHandler was not configured properly");
@@ -61,7 +61,7 @@ void testEventTranslationExceptionDoesNotCauseAsyncEventException() {
assertThrows(TestMessageException.class, () -> ((AbstractLogger) log)
.logMessage("com.foo.Bar", Level.INFO, null, exceptionThrowingMessage, null));
- CoreLoggerContexts.stopLoggerContext(); // stop async thread
+ ctx.stop(); // stop async thread
assertFalse(
TestExceptionHandler.EVENT_EXCEPTION_ENCOUNTERED, "ExceptionHandler encountered an event exception");
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerLocationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.java
similarity index 70%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerLocationTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.java
index b9bc4da8c30..81899d4b0f7 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerLocationTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -22,30 +22,31 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
-import org.apache.logging.log4j.LogManager;
+import java.nio.file.Path;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerLocationTest.xml")
-@CleanUpFiles("target/AsyncLoggerLocationTest.log")
public class AsyncLoggerLocationTest {
+ @TempLoggingDir
+ private static Path loggingPath;
+
@Test
- public void testAsyncLogWritesToLog() throws Exception {
- final File file = new File("target", "AsyncLoggerLocationTest.log");
+ @LoggerContextSource
+ public void testAsyncLogWritesToLog(final LoggerContext ctx) throws Exception {
+ final File file = loggingPath.resolve("AsyncLoggerLocationTest.log").toFile();
// System.out.println(f.getAbsolutePath());
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ final Logger log = ctx.getLogger("com.foo.Bar");
final String msg = "Async logger msg with location";
log.info(msg);
- CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
+ ctx.stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.java
similarity index 97%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.java
index 069fef4f34f..2ab6d4e1c86 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerNanoTimeTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -35,7 +35,7 @@
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@LoggerContextSource("NanoTimeToFileTest.xml")
+@LoggerContextSource
public class AsyncLoggerNanoTimeTest {
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTest.java
similarity index 75%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTest.java
index 99ac7c374f2..a5e48de0d9b 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -23,32 +23,34 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.nio.file.Path;
import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.time.internal.DummyNanoClock;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerTest.xml")
public class AsyncLoggerTest {
+ @TempLoggingDir
+ private static Path loggingPath;
+
@Test
- public void testAsyncLogWritesToLog() throws Exception {
- final File file = new File("target", "AsyncLoggerTest.log");
- // System.out.println(f.getAbsolutePath());
- file.delete();
+ @LoggerContextSource
+ public void testAsyncLogWritesToLog(final LoggerContext ctx) throws Exception {
+ final File file = loggingPath.resolve("AsyncLoggerTest.log").toFile();
- final AsyncLogger log = (AsyncLogger) LogManager.getLogger("com.foo.Bar");
+ final AsyncLogger log = (AsyncLogger) ctx.getLogger("com.foo.Bar");
assertTrue(log.getNanoClock() instanceof DummyNanoClock);
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
- CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
+ ctx.stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnErrorTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.java
similarity index 95%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnErrorTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.java
index c8f413d74ab..f66e1d76d76 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTestArgumentFreedOnErrorTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -31,7 +31,6 @@
import org.junitpioneer.jupiter.SetSystemProperty;
@Tag("async")
-@SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "log4j2-console.xml")
@SetSystemProperty(key = Log4jPropertyKey.Constant.GC_ENABLE_DIRECT_ENCODERS, value = "true")
@SetSystemProperty(key = Log4jPropertyKey.Constant.ASYNC_LOGGER_FORMAT_MESSAGES_IN_BACKGROUND, value = "true")
@ContextSelectorType(AsyncLoggerContextSelector.class)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerThreadContextTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerThreadContextTest.java
similarity index 79%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerThreadContextTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerThreadContextTest.java
index 69b1753f9ae..8741a347b1f 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerThreadContextTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerThreadContextTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -23,12 +23,11 @@
import java.io.File;
import java.io.FileReader;
import java.nio.file.Path;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
-import org.apache.logging.log4j.test.junit.SetTestProperty;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Tag;
@@ -36,7 +35,6 @@
@Tag("async")
@UsingStatusListener
-@SetTestProperty(key = "Configuration.file", value = "AsyncLoggerThreadContextTest.xml")
@ContextSelectorType(AsyncLoggerContextSelector.class)
public class AsyncLoggerThreadContextTest {
@@ -44,18 +42,17 @@ public class AsyncLoggerThreadContextTest {
private static Path loggingPath;
@Test
- public void testAsyncLogWritesToLog() throws Exception {
+ @LoggerContextSource
+ public void testAsyncLogWritesToLog(final LoggerContext ctx) throws Exception {
final File file = loggingPath.resolve("AsyncLoggerTest.log").toFile();
- // System.out.println(f.getAbsolutePath());
- file.delete();
ThreadContext.push("stackvalue");
ThreadContext.put("KEY", "mapvalue");
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ final Logger log = ctx.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
- CoreLoggerContexts.stopLoggerContext(false, file); // stop async thread
+ ctx.stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(file));
final String line1 = reader.readLine();
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTimestampMessageTest.java
similarity index 96%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTimestampMessageTest.java
index 982449067cf..89912ae0920 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerTimestampMessageTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerTimestampMessageTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +43,7 @@
*/
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@LoggerContextSource("AsyncLoggerTimestampMessageTest.xml")
+@LoggerContextSource
public class AsyncLoggerTimestampMessageTest {
@Factory
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerUseAfterShutdownTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerUseAfterShutdownTest.java
similarity index 61%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerUseAfterShutdownTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerUseAfterShutdownTest.java
index 73ec29efb31..912d2409c3d 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerUseAfterShutdownTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggerUseAfterShutdownTest.java
@@ -14,38 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
-import org.apache.logging.log4j.core.test.CoreLoggerContexts;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.message.SimpleMessage;
-import org.apache.logging.log4j.spi.AbstractLogger;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
-import org.junitpioneer.jupiter.SetSystemProperty;
/**
* Test for LOG4J2-639
*/
@Tag("async")
@Tag("functional")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
public class AsyncLoggerUseAfterShutdownTest {
+
@Test
- @SetSystemProperty(
- key = Log4jPropertyKey.Constant.CONTEXT_SELECTOR_CLASS_NAME,
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
- @SetSystemProperty(key = Log4jPropertyKey.Constant.CONFIG_LOCATION, value = "AsyncLoggerTest.xml")
- public void testNoErrorIfLogAfterShutdown() throws Exception {
- final Logger log = LogManager.getLogger("com.foo.Bar");
+ @LoggerContextSource
+ public void testNoErrorIfLogAfterShutdown(final LoggerContext ctx) throws Exception {
+ final Logger log = ctx.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
- CoreLoggerContexts.stopLoggerContext(); // stop async thread
+ ctx.stop(); // stop async thread
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
- ((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
+ log.logMessage(Level.INFO, null, "com.foo.Bar", null, new SimpleMessage("msg"), null);
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncAppenderTest.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncAppenderTest.java
index cb0c87d338c..04ca49d4db9 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncAppenderTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncLoggerConfigTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncLoggerConfigTest.java
similarity index 95%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncLoggerConfigTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncLoggerConfigTest.java
index 4256906f11c..0564601b315 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncLoggerConfigTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncLoggerConfigTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -40,7 +40,7 @@ public ContextSelector contextSelector(final ConfigurableInstanceFactory injecto
}
@Test
- @LoggerContextSource("AsyncLoggersWithAsyncLoggerConfigTest.xml")
+ @LoggerContextSource
public void testLoggingWorks(final Logger logger, @Named("List") final ListAppender appender) throws Exception {
logger.error("This is a test");
logger.warn("Hello world!");
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncRootReloadTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncRootReloadTest.java
similarity index 75%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncRootReloadTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncRootReloadTest.java
index bfe7ac3a32a..bb7e1cecf0b 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncRootReloadTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncRootReloadTest.java
@@ -14,15 +14,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
-import org.apache.logging.log4j.Logger;
+import java.nio.file.Path;
+import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.util.FileUtils;
-import org.apache.logging.log4j.test.junit.CleanUpFiles;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@@ -33,16 +34,16 @@
@Tag("sleepy")
public class AsyncRootReloadTest {
- private static final String ISSUE = "LOG4J2-807";
- private static final String ISSUE_CONFIG = ISSUE + ".xml";
- private static final String LOG = "target/" + ISSUE + ".log";
- private static final String RESOURCE = "classpath:" + ISSUE_CONFIG;
+ private static final String ISSUE_CONFIG =
+ "/" + AsyncRootReloadTest.class.getName().replace('.', '/') + ".xml";
+
+ @TempLoggingDir
+ private Path loggingPath;
@Test
- @CleanUpFiles(LOG)
- @LoggerContextSource(RESOURCE)
+ @LoggerContextSource
public void testLog4j2_807(final Logger logger) throws InterruptedException, URISyntaxException {
- final URL url = AsyncRootReloadTest.class.getResource("/" + ISSUE_CONFIG);
+ final URL url = AsyncRootReloadTest.class.getResource(ISSUE_CONFIG);
final File configFile = FileUtils.fileFromUri(url.toURI());
logger.info("Log4j configured, will be reconfigured in approx. 5 sec");
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
similarity index 94%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
index 4b28ed58f08..c8d57007bc1 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncThreadContextTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/AsyncThreadContextTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.waitAtMost;
@@ -22,6 +22,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.net.URI;
+import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
@@ -35,7 +36,6 @@
import org.apache.logging.log4j.core.selector.ClassLoaderContextSelector;
import org.apache.logging.log4j.core.selector.ContextSelector;
import org.apache.logging.log4j.core.test.CoreLoggerContexts;
-import org.apache.logging.log4j.core.util.NetUtils;
import org.apache.logging.log4j.plugins.di.DI;
import org.apache.logging.log4j.spi.LoggingSystemProperty;
import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
@@ -67,16 +67,22 @@ public class AsyncThreadContextTest {
private static Path loggingPath;
enum Mode {
- ALL_ASYNC(AsyncLoggerContextSelector.class, "AsyncLoggerThreadContextTest.xml"),
- MIXED(ClassLoaderContextSelector.class, "AsyncLoggerConfigThreadContextTest.xml"),
- BOTH_ALL_ASYNC_AND_MIXED(AsyncLoggerContextSelector.class, "AsyncLoggerConfigThreadContextTest.xml");
+ ALL_ASYNC(AsyncLoggerContextSelector.class),
+ MIXED(ClassLoaderContextSelector.class),
+ BOTH_ALL_ASYNC_AND_MIXED(AsyncLoggerContextSelector.class);
final Class extends ContextSelector> contextSelectorType;
final URI configUri;
- Mode(final Class extends ContextSelector> contextSelectorType, final String file) {
+ Mode(final Class extends ContextSelector> contextSelectorType) {
this.contextSelectorType = contextSelectorType;
- configUri = NetUtils.toURI(file);
+ try {
+ configUri = AsyncThreadContextTest.class
+ .getResource(AsyncThreadContextTest.class.getSimpleName() + "/" + name() + ".xml")
+ .toURI();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelectorTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelectorTest.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelectorTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelectorTest.java
index dc38a338644..a0256ee8ef4 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BasicAsyncLoggerContextSelectorTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/BasicAsyncLoggerContextSelectorTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java
new file mode 100644
index 00000000000..9f92ff02c6b
--- /dev/null
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DefaultIncludeLocationTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.async.logger;
+
+import java.util.stream.Stream;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.config.NullConfiguration;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class DefaultIncludeLocationTest {
+
+ private static final String LOGGER_NAME = DefaultIncludeLocationTest.class.getName();
+
+ private static Stream loggerConfigs(final Configuration config) {
+ return Stream.of(
+ Arguments.of(
+ LoggerConfig.newBuilder()
+ .setConfig(config)
+ .setLoggerName(LOGGER_NAME)
+ .build(),
+ true),
+ Arguments.of(
+ LoggerConfig.RootLogger.newRootBuilder()
+ .setConfig(config)
+ .build(),
+ true),
+ Arguments.of(
+ AsyncLoggerConfig.newAsyncBuilder()
+ .setConfig(config)
+ .setLoggerName(LOGGER_NAME)
+ .build(),
+ false),
+ Arguments.of(
+ AsyncLoggerConfig.RootLogger.newAsyncRootBuilder()
+ .setConfig(config)
+ .build(),
+ false));
+ }
+
+ static Stream loggerContextDefaultLocation() {
+ final LoggerContext ctx = new LoggerContext("sync");
+ ctx.setProperties(PropertiesUtil.getProperties());
+ final NullConfiguration config = new NullConfiguration(ctx);
+ ctx.setConfiguration(config);
+ return loggerConfigs(config);
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ void loggerContextDefaultLocation(final LoggerConfig loggerConfig, final boolean expected) {
+ Assertions.assertThat(loggerConfig.isIncludeLocation())
+ .as("Default `includeLocation` value")
+ .isEqualTo(expected);
+ }
+
+ static Stream asyncLoggerContextDefaultLocation() {
+ final AsyncLoggerContext ctx = new AsyncLoggerContext("async");
+ ctx.setProperties(PropertiesUtil.getProperties());
+ final NullConfiguration config = new NullConfiguration(ctx);
+ ctx.setConfiguration(config);
+ return loggerConfigs(config).map(args -> (LoggerConfig) args.get()[0]);
+ }
+
+ @ParameterizedTest
+ @MethodSource
+ void asyncLoggerContextDefaultLocation(final LoggerConfig loggerConfig) {
+ Assertions.assertThat(loggerConfig.isIncludeLocation())
+ .as("Default `includeLocation` value")
+ .isFalse();
+ }
+}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationInvalidTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationInvalidTest.java
similarity index 97%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationInvalidTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationInvalidTest.java
index aec3757813b..c7742987d5e 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationInvalidTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationInvalidTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.java
index 16dedf40372..190dbee16bc 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/GarbageFreeAsyncThreadContextTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/GarbageFreeAsyncThreadContextTest.java
similarity index 97%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/GarbageFreeAsyncThreadContextTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/GarbageFreeAsyncThreadContextTest.java
index 8dab35c708c..5bb8bf789c6 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/GarbageFreeAsyncThreadContextTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/GarbageFreeAsyncThreadContextTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import java.nio.file.Path;
import org.apache.logging.log4j.test.TestProperties;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.java
similarity index 96%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.java
index 7f0a872616b..220cad08a77 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/Log4j2Jira1688AsyncTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
@@ -35,7 +35,7 @@
*/
@Tag("async")
@ContextSelectorType(AsyncLoggerContextSelector.class)
-@LoggerContextSource("log4j-list.xml")
+@LoggerContextSource
public class Log4j2Jira1688AsyncTest {
private static Object[] createArray(final int size) {
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java
similarity index 63%
rename from log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java
index 51975ed947f..8a2161c955e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/selector/CoreContextSelectors.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest.java
@@ -14,17 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.selector;
+package org.apache.logging.log4j.async.logger;
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
-import org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector;
+import org.apache.logging.log4j.core.test.config.AbstractNestedLoggerConfigTest;
-public class CoreContextSelectors {
-
- public static final Class>[] CLASSES = new Class>[] {
- ClassLoaderContextSelector.class,
- BasicContextSelector.class,
- AsyncLoggerContextSelector.class,
- BasicAsyncLoggerContextSelector.class
- };
-}
+public class NestedAsyncLoggerConfigTest extends AbstractNestedLoggerConfigTest {}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
similarity index 53%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
index 2dc85a0974f..1e5e4bf3bc0 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAbstractTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncAbstractTest.java
@@ -14,150 +14,72 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
-import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import com.lmax.disruptor.RingBuffer;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.List;
import java.util.Optional;
-import java.util.Stack;
import java.util.concurrent.CountDownLatch;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.Appender;
-import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.appender.AsyncAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
-import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.async.QueueFullAbstractTest;
import org.apache.logging.log4j.status.StatusData;
-import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.test.ListStatusListener;
-import org.apache.logging.log4j.test.junit.UsingStatusListener;
-import org.apache.logging.log4j.util.ReflectionUtil;
-import org.junit.jupiter.api.Tag;
-import org.junit.jupiter.api.Timeout;
-import org.junit.jupiter.api.Timeout.ThreadMode;
-/**
- * Tests queue full scenarios abstract superclass.
- */
-@Tag("async")
-@UsingStatusListener
-@Timeout(value = 5, unit = SECONDS, threadMode = ThreadMode.SEPARATE_THREAD)
-public abstract class QueueFullAbstractTest {
- protected static boolean TRACE = Boolean.getBoolean(QueueFullAbstractTest.class.getSimpleName() + ".TRACE");
- protected BlockingAppender blockingAppender;
- protected Unlocker unlocker;
-
- protected static final String APPENDER_NAME = "Blocking";
- protected static final int BUFFER_COUNT = 128;
- protected static final int MESSAGE_COUNT = BUFFER_COUNT + 2;
- protected static final Logger LOGGER = StatusLogger.getLogger();
-
- protected static class Unlocker extends Thread {
-
- final CountDownLatch countDownLatch;
- final BlockingAppender blockingAppender;
-
- Unlocker(final CountDownLatch countDownLatch, final BlockingAppender blockingAppender) {
- this.countDownLatch = countDownLatch;
- this.blockingAppender = blockingAppender;
- }
-
- @Override
- public void run() {
- try {
- countDownLatch.await();
- LOGGER.info("Unlocker activated. Sleeping 500 millis before taking action...");
- Thread.sleep(500);
- } catch (final InterruptedException e) {
- throw new RuntimeException(e);
- }
- LOGGER.info("Unlocker signalling BlockingAppender to proceed...");
- blockingAppender.countDownLatch.countDown();
- }
- }
-
- protected static class DomainObject {
-
- private final Logger innerLogger;
- private final Unlocker unlocker;
- private final int count;
-
- public DomainObject(final Logger innerLogger, final Unlocker unlocker, final int loggingCount) {
- this.innerLogger = innerLogger;
- this.unlocker = unlocker;
- this.count = loggingCount;
- }
-
- @Override
- public String toString() {
- for (int i = 0; i < count; i++) {
- LOGGER.info(
- "DomainObject logging message {}. Ring buffer capacity was {}, countdown latch was {}.",
- i,
- asyncRemainingCapacity(innerLogger),
- unlocker.countDownLatch.getCount());
- unlocker.countDownLatch.countDown();
- innerLogger.info("Logging in toString() #{}", i);
- }
- return "Who's bad?!";
- }
- }
+public abstract class QueueFullAsyncAbstractTest extends QueueFullAbstractTest {
private ListStatusListener statusListener;
- protected void testNormalQueueFullKeepsMessagesInOrder(
- final LoggerContext ctx, final BlockingAppender blockingAppender) throws Exception {
- checkConfig(ctx);
- final Logger logger = ctx.getLogger(getClass());
+ protected static void assertAsyncLogger(final LoggerContext ctx, final int expectedBufferSize) {
+ assertThat(ctx).isInstanceOf(AsyncLoggerContext.class);
+ assertThat(((AsyncLoggerContext) ctx)
+ .getAsyncLoggerDisruptor()
+ .getRingBuffer()
+ .getBufferSize())
+ .isEqualTo(expectedBufferSize);
- blockingAppender.countDownLatch = new CountDownLatch(1);
- final Unlocker unlocker = new Unlocker(new CountDownLatch(MESSAGE_COUNT - 1), blockingAppender);
- unlocker.start();
- asyncTest(logger, unlocker, blockingAppender);
- unlocker.join();
+ final Configuration config = ctx.getConfiguration();
+ assertThat(config).isNotNull();
+ assertThat(config.getRootLogger()).isNotInstanceOf(AsyncLoggerConfig.class);
}
- protected void checkConfig(final LoggerContext ctx) throws Exception {}
+ protected static void assertAsyncLoggerConfig(final LoggerContext ctx, final int expectedBufferSize) {
+ assertThat(ctx).isNotInstanceOf(AsyncLoggerContext.class);
- protected static void asyncTest(
- final Logger logger, final Unlocker unlocker, final BlockingAppender blockingAppender) {
- for (int i = 0; i < MESSAGE_COUNT; i++) {
- LOGGER.info(
- "Test logging message {}. Ring buffer capacity was {}, countdown latch was {}.",
- i,
- asyncRemainingCapacity(logger),
- unlocker.countDownLatch.getCount());
- unlocker.countDownLatch.countDown();
- final String param = "I'm innocent";
- logger.info("Logging innocent object #{}: {}", i, param);
- }
- LOGGER.info(
- "Waiting for message delivery: blockingAppender.logEvents.count={}.",
- blockingAppender.logEvents.size());
- while (blockingAppender.logEvents.size() < MESSAGE_COUNT) {
- Thread.yield();
- }
- LOGGER.info(
- "All {} message have been delivered: blockingAppender.logEvents.count={}.",
- MESSAGE_COUNT,
- blockingAppender.logEvents.size());
+ final Configuration config = ctx.getConfiguration();
+ assertThat(config).isNotNull();
+ assertThat(config.getRootLogger()).isInstanceOf(AsyncLoggerConfig.class);
+ final DisruptorConfiguration disruptorConfig = config.getExtension(DisruptorConfiguration.class);
+ final AsyncLoggerConfigDisruptor disruptor =
+ (AsyncLoggerConfigDisruptor) disruptorConfig.getAsyncLoggerConfigDelegate();
+ assertThat(disruptor.getRingBuffer().getBufferSize()).isEqualTo(expectedBufferSize);
+ }
- final Stack actual = transform(blockingAppender.logEvents);
- for (int i = 0; i < MESSAGE_COUNT; i++) {
- assertThat(actual.pop()).isEqualTo("Logging innocent object #%d: I'm innocent", i);
+ @Override
+ protected long asyncRemainingCapacity(final Logger logger) {
+ if (logger instanceof final AsyncLogger asyncLogger) {
+ return Optional.ofNullable(asyncLogger.getAsyncLoggerDisruptor())
+ .map(AsyncLoggerDisruptor::getRingBuffer)
+ .map(RingBuffer::remainingCapacity)
+ .orElse(0L);
+ } else {
+ final LoggerConfig loggerConfig = ((org.apache.logging.log4j.core.Logger) logger).get();
+ if (loggerConfig instanceof final AsyncLoggerConfig asyncLoggerConfig) {
+ return Optional.ofNullable(
+ (AsyncLoggerConfigDisruptor) asyncLoggerConfig.getAsyncLoggerConfigDelegate())
+ .map(AsyncLoggerConfigDisruptor::getRingBuffer)
+ .map(RingBuffer::remainingCapacity)
+ .orElse(0L);
+ }
}
- assertThat(actual).isEmpty();
+ return super.asyncRemainingCapacity(logger);
}
public void testLoggingFromToStringCausesOutOfOrderMessages(
@@ -217,90 +139,30 @@ void asyncRecursiveTest(final Logger logger, final Unlocker unlocker, final Bloc
assertThat(actual).hasSize(MESSAGE_COUNT).contains(expected);
}
- static Stack transform(final List logEvents) {
- final List filtered = getMessages(logEvents);
- Collections.reverse(filtered);
- final Stack result = new Stack<>();
- result.addAll(filtered);
- return result;
- }
+ protected class DomainObject {
+
+ private final Logger innerLogger;
+ private final Unlocker unlocker;
+ private final int count;
- static List getMessages(final List logEvents) {
- final List filtered = new ArrayList<>(logEvents.size());
- for (LogEvent event : logEvents) {
- filtered.add(event.getMessage().getFormattedMessage());
+ public DomainObject(final Logger innerLogger, final Unlocker unlocker, final int loggingCount) {
+ this.innerLogger = innerLogger;
+ this.unlocker = unlocker;
+ this.count = loggingCount;
}
- return filtered;
- }
- static long asyncRemainingCapacity(final Logger logger) {
- if (logger instanceof AsyncLogger asyncLogger) {
- return Optional.ofNullable(asyncLogger.getAsyncLoggerDisruptor())
- .map(AsyncLoggerDisruptor::getRingBuffer)
- .map(RingBuffer::remainingCapacity)
- .orElse(0L);
- } else {
- final LoggerConfig loggerConfig = ((org.apache.logging.log4j.core.Logger) logger).get();
- if (loggerConfig instanceof AsyncLoggerConfig asyncLoggerConfig) {
- return Optional.ofNullable(
- (AsyncLoggerConfigDisruptor) asyncLoggerConfig.getAsyncLoggerConfigDelegate())
- .map(AsyncLoggerConfigDisruptor::getRingBuffer)
- .map(RingBuffer::remainingCapacity)
- .orElse(0L);
- } else {
- final Appender async = loggerConfig.getAppenders().get("async");
- if (async instanceof AsyncAppender) {
- return ((AsyncAppender) async).getQueueCapacity();
- }
+ @Override
+ public String toString() {
+ for (int i = 0; i < count; i++) {
+ LOGGER.info(
+ "DomainObject logging message {}. Ring buffer capacity was {}, countdown latch was {}.",
+ i,
+ asyncRemainingCapacity(innerLogger),
+ unlocker.countDownLatch.getCount());
+ unlocker.countDownLatch.countDown();
+ innerLogger.info("Logging in toString() #{}", i);
}
+ return "Who's bad?!";
}
- throw new IllegalStateException("Neither Async Loggers nor AsyncAppender are configured");
- }
-
- protected static Field field(final Class> c, final String name) throws NoSuchFieldException {
- final Field f = c.getDeclaredField(name);
- ReflectionUtil.makeAccessible(f);
- return f;
- }
-
- protected static void assertAsyncAppender(final LoggerContext ctx) {
- assertThat(ctx).isNotInstanceOf(AsyncLoggerContext.class);
-
- final Configuration config = ctx.getConfiguration();
- assertThat(config).isNotNull();
- assertThat(config.getRootLogger()).isNotInstanceOf(AsyncLoggerConfig.class);
-
- final Collection appenders =
- config.getRootLogger().getAppenders().values();
- assertThat(appenders).hasSize(1).allMatch(AsyncAppender.class::isInstance);
- }
-
- protected static void assertAsyncLogger(final LoggerContext ctx, final int expectedBufferSize) {
- assertThat(ctx).isInstanceOf(AsyncLoggerContext.class);
- assertThat(((AsyncLoggerContext) ctx)
- .getAsyncLoggerDisruptor()
- .getRingBuffer()
- .getBufferSize())
- .isEqualTo(expectedBufferSize);
-
- final Configuration config = ctx.getConfiguration();
- assertThat(config).isNotNull();
- assertThat(config.getRootLogger()).isNotInstanceOf(AsyncLoggerConfig.class);
- }
-
- protected static void assertAsyncLoggerConfig(final LoggerContext ctx, final int expectedBufferSize) {
- assertThat(ctx).isNotInstanceOf(AsyncLoggerContext.class);
-
- final Configuration config = ctx.getConfiguration();
- assertThat(config).isNotNull();
- assertThat(config.getRootLogger()).isInstanceOf(AsyncLoggerConfig.class);
- final DisruptorConfiguration disruptorConfig = config.getExtension(DisruptorConfiguration.class);
- final AsyncLoggerConfigDisruptor disruptor =
- (AsyncLoggerConfigDisruptor) disruptorConfig.getAsyncLoggerConfigDelegate();
- assertThat(disruptor.getRingBuffer().getBufferSize()).isEqualTo(expectedBufferSize);
- }
-
- protected static void assertFormatMessagesInBackground() {
- assertThat(Constants.FORMAT_MESSAGES_IN_BACKGROUND).isTrue();
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger2Test.java
similarity index 89%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger2Test.java
index 5699a286302..55e0b74025d 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest2.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger2Test.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -24,11 +24,10 @@
* is immutable.
*/
@SetTestProperty(key = "AsyncLogger.formatMsg", value = "true")
-public class QueueFullAsyncLoggerTest2 extends QueueFullAsyncLoggerTest {
+public class QueueFullAsyncLogger2Test extends QueueFullAsyncAbstractTest {
@Override
protected void checkConfig(final LoggerContext ctx) {
- super.checkConfig(ctx);
assertFormatMessagesInBackground();
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
similarity index 85%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
index 51be5edf8d5..d9416e79b8e 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest3.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLogger3Test.java
@@ -14,39 +14,41 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.concurrent.CountDownLatch;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.GarbageCollectionHelper;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.async.AsyncQueueFullPolicyFactory;
+import org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.message.Message;
import org.apache.logging.log4j.test.junit.SetTestProperty;
+import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
@SetTestProperty(key = "AsyncLogger.formatMsg", value = "true")
@SetTestProperty(key = "AsyncLogger.queueFullPolicy", value = "Discard")
-public class QueueFullAsyncLoggerTest3 extends QueueFullAbstractTest {
+public class QueueFullAsyncLogger3Test extends QueueFullAsyncAbstractTest {
@Override
protected void checkConfig(final LoggerContext ctx) {
assertAsyncLogger(ctx, 128);
assertFormatMessagesInBackground();
- assertThat(AsyncQueueFullPolicyFactory.create()).isInstanceOf(DiscardingAsyncQueueFullPolicy.class);
+ Assertions.assertThat(AsyncQueueFullPolicyFactory.create()).isInstanceOf(DiscardingAsyncQueueFullPolicy.class);
}
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfig2Test.java
similarity index 91%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfig2Test.java
index 918fe6c13ed..48e34790368 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest2.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfig2Test.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -23,7 +23,7 @@
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "AsyncLogger.formatMsg", value = "true")
-public class QueueFullAsyncLoggerConfigTest2 extends QueueFullAsyncLoggerConfigTest {
+public class QueueFullAsyncLoggerConfig2Test extends QueueFullAsyncLoggerConfigTest {
@Override
protected void checkConfig(final LoggerContext ctx) throws ReflectiveOperationException {
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToString2Test.java
similarity index 92%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToString2Test.java
index d503e343679..9d886ce5952 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest2.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToString2Test.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -23,7 +23,7 @@
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "AsyncLogger.formatMsg", value = "true")
-public class QueueFullAsyncLoggerConfigLoggingFromToStringTest2
+public class QueueFullAsyncLoggerConfigLoggingFromToString2Test
extends QueueFullAsyncLoggerConfigLoggingFromToStringTest {
@Override
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java
similarity index 93%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java
index 7b1c0692736..900e1711e4f 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToStringTest.java
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.assertThat;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -30,7 +31,7 @@
*/
@SetTestProperty(key = "Web.isWebApp", value = "false")
@SetTestProperty(key = "AsyncLoggerConfig.ringBufferSize", value = "128")
-public class QueueFullAsyncLoggerConfigLoggingFromToStringTest extends QueueFullAbstractTest {
+public class QueueFullAsyncLoggerConfigLoggingFromToStringTest extends QueueFullAsyncAbstractTest {
@Override
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigTest.java
similarity index 89%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigTest.java
index de6a0cd6744..0eb7e853b5f 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigTest.java
@@ -14,9 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -26,7 +27,7 @@
* Tests queue full scenarios with AsyncLoggers in configuration.
*/
@SetTestProperty(key = "AsyncLoggerConfig.ringBufferSize", value = "128")
-public class QueueFullAsyncLoggerConfigTest extends QueueFullAbstractTest {
+public class QueueFullAsyncLoggerConfigTest extends QueueFullAsyncAbstractTest {
@Override
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
similarity index 86%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
index db061b2cafd..d95ec2966a1 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerLoggingFromToStringTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerLoggingFromToStringTest.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -25,11 +27,9 @@
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
-public class QueueFullAsyncLoggerLoggingFromToStringTest extends QueueFullAbstractTest {
+public class QueueFullAsyncLoggerLoggingFromToStringTest extends QueueFullAsyncAbstractTest {
@Override
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
similarity index 84%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
index eb83ab4f280..f1e8e441073 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerTest.java
@@ -14,9 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.async.BlockingAppender;
+import org.apache.logging.log4j.core.test.junit.ContextSelectorType;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.core.test.junit.Named;
import org.apache.logging.log4j.test.junit.SetTestProperty;
@@ -25,11 +27,9 @@
/**
* Tests queue full scenarios with pure AsyncLoggers (all loggers async).
*/
-@SetTestProperty(
- key = "LoggerContext.selector",
- value = "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
+@ContextSelectorType(AsyncLoggerContextSelector.class)
@SetTestProperty(key = "AsyncLogger.ringBufferSize", value = "128")
-public class QueueFullAsyncLoggerTest extends QueueFullAbstractTest {
+public class QueueFullAsyncLoggerTest extends QueueFullAsyncAbstractTest {
@Override
@Test
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTest.java
similarity index 99%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
rename to log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTest.java
index f2995c2461f..edefd4975c3 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java
+++ b/log4j-async-logger/src/test/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.async.logger;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
diff --git a/log4j-core-test/src/test/resources/AsyncWaitStrategyIncorrectFactoryConfigTest.xml b/log4j-async-logger/src/test/resources/AsyncWaitStrategyIncorrectFactoryConfigTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncWaitStrategyIncorrectFactoryConfigTest.xml
rename to log4j-async-logger/src/test/resources/AsyncWaitStrategyIncorrectFactoryConfigTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerConsoleTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerClassLoadDeadlockTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerConsoleTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerClassLoadDeadlockTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerConfigTest2.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.xml
similarity index 94%
rename from log4j-core-test/src/test/resources/AsyncLoggerConfigTest2.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.xml
index d4090ca4eef..188f173ac8e 100644
--- a/log4j-core-test/src/test/resources/AsyncLoggerConfigTest2.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig2Test.xml
@@ -18,7 +18,7 @@
diff --git a/log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.xml
similarity index 72%
rename from log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.xml
index 38a76f0a89a..188f173ac8e 100644
--- a/log4j-core-test/src/test/resources/RandomAccessFileAppenderLocationTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig3Test.xml
@@ -15,21 +15,22 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n
-
-
+
-
-
+
+
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfig4Test.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig4Test.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfig4Test.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfig4Test.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerConfigAutoFlushTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.xml
similarity index 94%
rename from log4j-core-test/src/test/resources/AsyncLoggerConfigAutoFlushTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.xml
index 32a9dda46cc..5dd6428cb60 100644
--- a/log4j-core-test/src/test/resources/AsyncLoggerConfigAutoFlushTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigAutoFlushTest.xml
@@ -18,7 +18,7 @@
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerConfigErrorOnFormat.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.xml
similarity index 94%
rename from log4j-core-test/src/test/resources/AsyncLoggerConfigErrorOnFormat.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.xml
index 8dd03842e17..3752763819a 100644
--- a/log4j-core-test/src/test/resources/AsyncLoggerConfigErrorOnFormat.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigErrorOnFormat.xml
@@ -18,7 +18,7 @@
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfigTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigTest.xml
diff --git a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.xml
similarity index 67%
rename from log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.xml
index 9e4f8445528..19fc5c1e9d9 100644
--- a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderLocationTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigUseAfterShutdownTest.xml
@@ -15,23 +15,25 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-
+
-
+
%d %p %c{1.} [%t] %X{aKey} %m %location %ex%n
-
-
-
-
+
-
-
-
+
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfigWithAsyncEnabledTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigWithAsyncEnabledTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggerConfigWithAsyncEnabledTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerConfigWithAsyncEnabledTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerCustomSelectorLocationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.xml
similarity index 91%
rename from log4j-core-test/src/test/resources/AsyncLoggerCustomSelectorLocationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.xml
index 30bfa3e9c17..35d0be64a78 100644
--- a/log4j-core-test/src/test/resources/AsyncLoggerCustomSelectorLocationTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerCustomSelectorLocationTest.xml
@@ -17,7 +17,7 @@
-->
-
%d %p %c{1.} [%t] %X{aKey} %location %m %ex%n
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerDefaultLocationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultLocationTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerDefaultLocationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerDefaultLocationTest.xml
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.xml
new file mode 100644
index 00000000000..d85749123be
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerEventTranslationExceptionTest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerLocationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.xml
similarity index 92%
rename from log4j-core-test/src/test/resources/AsyncLoggerLocationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.xml
index 18d69dbd9bb..ccffbc73905 100644
--- a/log4j-core-test/src/test/resources/AsyncLoggerLocationTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerLocationTest.xml
@@ -17,7 +17,7 @@
-->
-
%d %p %c{1.} [%t] %X{aKey} %location %m %ex%n
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.xml
new file mode 100644
index 00000000000..f86ce794216
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerNanoTimeTest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTest.xml
new file mode 100644
index 00000000000..c97bf21fc01
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTest.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+ %d %p %c{1.} [%t] %X{aKey} %location %m %ex%n
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.xml
new file mode 100644
index 00000000000..d85749123be
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTestArgumentFreedOnErrorTest.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerThreadContextTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerThreadContextTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerThreadContextTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerThreadContextTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerTimestampMessageTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTimestampMessageTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerTimestampMessageTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerTimestampMessageTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerUseAfterShutdownTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggerUseAfterShutdownTest.xml
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncAppenderTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/AsyncLoggersWithAsyncAppenderTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncAppenderTest.xml
diff --git a/log4j-core-test/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncLoggerConfigTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncLoggersWithAsyncLoggerConfigTest.xml
diff --git a/log4j-core-test/src/test/resources/LOG4J2-807.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncRootReloadTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/LOG4J2-807.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncRootReloadTest.xml
diff --git a/log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/ALL_ASYNC.xml
similarity index 73%
rename from log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/ALL_ASYNC.xml
index 146dd390cbe..5152369ea6b 100644
--- a/log4j-core-test/src/test/resources/RandomAccessFileAppenderTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/ALL_ASYNC.xml
@@ -17,19 +17,19 @@
-->
-
+
- %d %p %c{1.} [%t] %X{aKey} %m %location %ex%n
-
+ %p %c{1.} %X{KEY} %x %X %m%ex%n
-
+
+ configValue
+ configValue2
-
+
diff --git a/log4j-core-test/src/test/resources/AsyncLoggerConfigThreadContextTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/BOTH_ALL_ASYNC_AND_MIXED.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/AsyncLoggerConfigThreadContextTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/BOTH_ALL_ASYNC_AND_MIXED.xml
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/MIXED.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/MIXED.xml
new file mode 100644
index 00000000000..c0d4667a892
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/AsyncThreadContextTest/MIXED.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+ %p %c{1.} %X{KEY} %x %X %m%ex%n
+
+
+
+
+
+
+
+ %p %c{1.} %X{KEY} %x %X %m%ex%n
+
+
+
+
+
+
+
+ %p %c{1.} %X{KEY} %x %X %m%ex%n
+
+
+
+
+ %p %c{1.} %X{KEY} %x %X %m%ex%n
+
+
+
+
+
+
+ configValue
+ configValue2
+
+
+
+
+ configValue
+ configValue2
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/DisruptorConfigurationInvalidTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/DisruptorConfigurationInvalidTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/DisruptorConfigurationInvalidTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/DisruptorConfigurationInvalidTest.xml
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.xml
similarity index 91%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.xml
index f52b0d58c3b..2265a4963ef 100644
--- a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/DisruptorConfigurationTest.xml
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/DisruptorConfigurationTest.xml
@@ -27,5 +27,5 @@
+ class="org.apache.logging.log4j.async.logger.DisruptorConfigurationTest$YieldingWaitStrategyFactory" />
diff --git a/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.xml
new file mode 100644
index 00000000000..fd7fdf68522
--- /dev/null
+++ b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/Log4j2Jira1688AsyncTest.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/default-level.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/default-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/default-level.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/default-level.xml
diff --git a/log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/inherit-level.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/inherit-level.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/logger-config/AsyncLoggerConfig/inherit-level.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/NestedAsyncLoggerConfigTest/inherit-level.xml
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToStringTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigLoggingFromToStringTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigLoggingFromToStringTest.xml
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.xml b/log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAsyncLoggerConfigTest.xml
rename to log4j-async-logger/src/test/resources/org/apache/logging/log4j/async/logger/QueueFullAsyncLoggerConfigTest.xml
diff --git a/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java b/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
index a02814efb6c..f1656be526f 100644
--- a/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
+++ b/log4j-config-properties/src/test/java/org/apache/logging/log4j/config/properties/JavaPropsConfigurationFactoryTest.java
@@ -23,9 +23,9 @@
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.filter.ThresholdFilter;
import org.apache.logging.log4j.core.test.appender.ListAppender;
+import org.apache.logging.log4j.core.test.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Test;
diff --git a/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java b/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
index 02d21323ab7..8e88f321e09 100644
--- a/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
+++ b/log4j-config-yaml/src/test/java/org/apache/logging/log4j/config/yaml/YamlConfigurationFactoryTest.java
@@ -19,7 +19,7 @@
import java.io.IOException;
import java.nio.file.Path;
import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.core.config.AbstractConfigurationFactoryTest;
+import org.apache.logging.log4j.core.test.config.AbstractConfigurationFactoryTest;
import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
import org.junit.jupiter.api.Test;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java
similarity index 95%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java
index b7aea87421d..1feff3edd8c 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/GarbageCollectionHelper.java
@@ -18,7 +18,6 @@
import static org.junit.Assert.assertTrue;
-import com.google.common.io.ByteStreams;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
@@ -27,7 +26,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
public final class GarbageCollectionHelper implements Closeable, Runnable {
- private static final OutputStream sink = ByteStreams.nullOutputStream();
+ private static final OutputStream sink = OutputStream.nullOutputStream();
private final AtomicBoolean running = new AtomicBoolean();
private final CountDownLatch latch = new CountDownLatch(1);
private final Thread gcThread = new Thread(new Runnable() {
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/ThreadContextTestAccess.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/ThreadContextTestAccess.java
similarity index 100%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/ThreadContextTestAccess.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/ThreadContextTestAccess.java
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/LateConfigAbstractTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/LateConfigAbstractTest.java
new file mode 100644
index 00000000000..f87bce912ea
--- /dev/null
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/LateConfigAbstractTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import java.net.URI;
+import java.nio.file.Path;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
+import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.apache.logging.log4j.core.impl.Log4jContextFactory;
+
+public class LateConfigAbstractTest {
+
+ private static final String CONFIG = "LateConfigAbstractTest.xml";
+ // This class will be the caller of `Log4jContextFactory`
+ private static final String FQCN = Log4jContextFactory.class.getName();
+
+ protected static void testReconfiguration(final Log4jContextFactory factory, final Path loggingPath)
+ throws Exception {
+ try (final LoggerContext context = factory.getContext(FQCN, null, null, false)) {
+ final Configuration defaultConfig = context.getConfiguration();
+ assertThat(defaultConfig).isInstanceOf(DefaultConfiguration.class);
+
+ final URI configLocation =
+ LateConfigAbstractTest.class.getResource(CONFIG).toURI();
+ final LoggerContext context1 = factory.getContext(FQCN, null, null, false, configLocation, null);
+ assertThat(context1).isSameAs(context);
+ assertThat(loggingPath.resolve("test-xml.log")).exists();
+ final Configuration newConfig = context.getConfiguration();
+ assertThat(newConfig).isInstanceOf(XmlConfiguration.class);
+
+ final LoggerContext context2 = factory.getContext(FQCN, null, null, false);
+ assertThat(context2).isSameAs(context);
+ final Configuration sameConfig = context.getConfiguration();
+ assertSame(newConfig, sameConfig, "Configuration should not have been reset");
+ }
+ }
+}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/TestPatternConverters.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/TestPatternConverters.java
similarity index 97%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/TestPatternConverters.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/TestPatternConverters.java
index 3f06139531d..d1400e40d05 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/TestPatternConverters.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/TestPatternConverters.java
@@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core;
+package org.apache.logging.log4j.core.test;
+import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;
import org.apache.logging.log4j.plugins.Namespace;
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BlockingAppender.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/BlockingAppender.java
similarity index 98%
rename from log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BlockingAppender.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/BlockingAppender.java
index 5ffabe81182..ddee82e6208 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/BlockingAppender.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/BlockingAppender.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.async;
+package org.apache.logging.log4j.core.test.async;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java
new file mode 100644
index 00000000000..4943de6314c
--- /dev/null
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.test.async;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Stack;
+import java.util.concurrent.CountDownLatch;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.appender.AsyncAppender;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.util.Constants;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.Timeout.ThreadMode;
+
+/**
+ * Tests queue full scenarios abstract superclass.
+ */
+@Tag("async")
+@UsingStatusListener
+@Timeout(value = 5, unit = SECONDS, threadMode = ThreadMode.SEPARATE_THREAD)
+public abstract class QueueFullAbstractTest {
+ protected static boolean TRACE = Boolean.getBoolean(QueueFullAbstractTest.class.getSimpleName() + ".TRACE");
+ protected BlockingAppender blockingAppender;
+ protected Unlocker unlocker;
+
+ protected static final String APPENDER_NAME = "Blocking";
+ protected static final int BUFFER_COUNT = 128;
+ protected static final int MESSAGE_COUNT = BUFFER_COUNT + 2;
+ protected static final Logger LOGGER = StatusLogger.getLogger();
+
+ protected static class Unlocker extends Thread {
+
+ public final CountDownLatch countDownLatch;
+ final BlockingAppender blockingAppender;
+
+ public Unlocker(final CountDownLatch countDownLatch, final BlockingAppender blockingAppender) {
+ this.countDownLatch = countDownLatch;
+ this.blockingAppender = blockingAppender;
+ }
+
+ @Override
+ public void run() {
+ try {
+ countDownLatch.await();
+ LOGGER.info("Unlocker activated. Sleeping 500 millis before taking action...");
+ Thread.sleep(500);
+ } catch (final InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ LOGGER.info("Unlocker signalling BlockingAppender to proceed...");
+ blockingAppender.countDownLatch.countDown();
+ }
+ }
+
+ protected void testNormalQueueFullKeepsMessagesInOrder(
+ final LoggerContext ctx, final BlockingAppender blockingAppender) throws Exception {
+ checkConfig(ctx);
+ final Logger logger = ctx.getLogger(getClass());
+
+ blockingAppender.countDownLatch = new CountDownLatch(1);
+ final Unlocker unlocker = new Unlocker(new CountDownLatch(MESSAGE_COUNT - 1), blockingAppender);
+ unlocker.start();
+ asyncTest(logger, unlocker, blockingAppender);
+ unlocker.join();
+ }
+
+ protected abstract void checkConfig(final LoggerContext ctx) throws Exception;
+
+ protected void asyncTest(final Logger logger, final Unlocker unlocker, final BlockingAppender blockingAppender) {
+ for (int i = 0; i < MESSAGE_COUNT; i++) {
+ LOGGER.info(
+ "Test logging message {}. Ring buffer capacity was {}, countdown latch was {}.",
+ i,
+ asyncRemainingCapacity(logger),
+ unlocker.countDownLatch.getCount());
+ unlocker.countDownLatch.countDown();
+ final String param = "I'm innocent";
+ logger.info("Logging innocent object #{}: {}", i, param);
+ }
+ LOGGER.info(
+ "Waiting for message delivery: blockingAppender.logEvents.count={}.",
+ blockingAppender.logEvents.size());
+ while (blockingAppender.logEvents.size() < MESSAGE_COUNT) {
+ Thread.yield();
+ }
+ LOGGER.info(
+ "All {} message have been delivered: blockingAppender.logEvents.count={}.",
+ MESSAGE_COUNT,
+ blockingAppender.logEvents.size());
+
+ final Stack actual = transform(blockingAppender.logEvents);
+ for (int i = 0; i < MESSAGE_COUNT; i++) {
+ assertThat(actual.pop()).isEqualTo("Logging innocent object #%d: I'm innocent", i);
+ }
+ assertThat(actual).isEmpty();
+ }
+
+ static Stack transform(final List logEvents) {
+ final List filtered = getMessages(logEvents);
+ Collections.reverse(filtered);
+ final Stack result = new Stack<>();
+ result.addAll(filtered);
+ return result;
+ }
+
+ static List getMessages(final List logEvents) {
+ final List filtered = new ArrayList<>(logEvents.size());
+ for (LogEvent event : logEvents) {
+ filtered.add(event.getMessage().getFormattedMessage());
+ }
+ return filtered;
+ }
+
+ protected long asyncRemainingCapacity(final Logger logger) {
+ final LoggerConfig loggerConfig = ((org.apache.logging.log4j.core.Logger) logger).get();
+ final Appender async = loggerConfig.getAppenders().get("async");
+ if (async instanceof AsyncAppender) {
+ return ((AsyncAppender) async).getQueueCapacity();
+ }
+ throw new IllegalStateException("Neither Async Loggers nor AsyncAppender are configured");
+ }
+
+ protected static void assertAsyncAppender(final LoggerContext ctx) {
+ final Configuration config = ctx.getConfiguration();
+ assertThat(config).isNotNull();
+
+ final Collection appenders =
+ config.getRootLogger().getAppenders().values();
+ assertThat(appenders).hasSize(1).allMatch(AsyncAppender.class::isInstance);
+ }
+
+ protected static void assertFormatMessagesInBackground() {
+ assertThat(Constants.FORMAT_MESSAGES_IN_BACKGROUND).isTrue();
+ }
+}
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/package-info.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/package-info.java
new file mode 100644
index 00000000000..666b01d2645
--- /dev/null
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/async/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+@Export
+@Version("3.0.0")
+package org.apache.logging.log4j.core.test.async;
+
+import org.osgi.annotation.bundle.Export;
+import org.osgi.annotation.versioning.Version;
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
similarity index 97%
rename from log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java
rename to log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
index 52f8ff9ee3c..a0b3fc45ac8 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/config/AbstractConfigurationFactoryTest.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractConfigurationFactoryTest.java
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.logging.log4j.core.config;
+package org.apache.logging.log4j.core.test.config;
import static org.apache.logging.log4j.util.Unbox.box;
import static org.junit.jupiter.api.Assertions.assertAll;
@@ -35,6 +35,7 @@
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
+import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.filter.ThreadContextMapFilter;
import org.apache.logging.log4j.util.Strings;
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java
new file mode 100644
index 00000000000..4c0a3cbb5f5
--- /dev/null
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/config/AbstractNestedLoggerConfigTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.logging.log4j.core.test.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
+import org.junit.jupiter.api.Test;
+
+public abstract class AbstractNestedLoggerConfigTest {
+
+ @Test
+ public void testInheritParentDefaultLevel() throws IOException {
+ final Configuration configuration = loadConfiguration("/default-level.xml");
+ try {
+ assertEquals(Level.ERROR, configuration.getLoggerConfig("com.foo").getLevel());
+ } finally {
+ configuration.stop();
+ }
+ }
+
+ @Test
+ public void testInheritParentLevel() throws IOException {
+ final Configuration configuration = loadConfiguration("/inherit-level.xml");
+ try {
+ assertEquals(Level.TRACE, configuration.getLoggerConfig("com.foo").getLevel());
+ } finally {
+ configuration.stop();
+ }
+ }
+
+ private Configuration loadConfiguration(final String resourcePath) throws IOException {
+ try (final InputStream in = getClass().getResourceAsStream(getClass().getSimpleName() + resourcePath)) {
+ final Configuration configuration =
+ new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in));
+ configuration.initialize();
+ configuration.start();
+ return configuration;
+ }
+ }
+}
diff --git a/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/LateConfigAbstractTest.xml b/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/LateConfigAbstractTest.xml
new file mode 100644
index 00000000000..8233fbf38bb
--- /dev/null
+++ b/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/LateConfigAbstractTest.xml
@@ -0,0 +1,57 @@
+
+
+
+
+ ${test:logging.path}/test-xml.log
+
+
+
+
+
+
+
+
+
+ %d %p %C{1.} [%t] %m%n
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAbstractTest.xml b/log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.xml
similarity index 100%
rename from log4j-core-test/src/test/resources/org/apache/logging/log4j/core/async/QueueFullAbstractTest.xml
rename to log4j-core-test/src/main/resources/org/apache/logging/log4j/core/test/async/QueueFullAbstractTest.xml
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
index 3263ed6f254..ab3a8f8fa66 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/LateConfigTest.java
@@ -16,34 +16,24 @@
*/
package org.apache.logging.log4j.core;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
-import java.net.URI;
import java.nio.file.Path;
import java.util.stream.Stream;
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
-import org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector;
-import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.DefaultConfiguration;
-import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
import org.apache.logging.log4j.core.impl.Log4jContextFactory;
import org.apache.logging.log4j.core.selector.BasicContextSelector;
import org.apache.logging.log4j.core.selector.ClassLoaderContextSelector;
import org.apache.logging.log4j.core.selector.ContextSelector;
+import org.apache.logging.log4j.core.test.LateConfigAbstractTest;
import org.apache.logging.log4j.plugins.di.ConfigurableInstanceFactory;
import org.apache.logging.log4j.plugins.di.DI;
import org.apache.logging.log4j.test.junit.TempLoggingDir;
+import org.apache.logging.log4j.test.junit.UsingStatusListener;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@Tag("functional")
-public class LateConfigTest {
-
- private static final String CONFIG = "/log4j-test1.xml";
- // This class will be the caller of `Log4jContextFactory`
- private static final String FQCN = Log4jContextFactory.class.getName();
+@UsingStatusListener
+public class LateConfigTest extends LateConfigAbstractTest {
@TempLoggingDir
private static Path loggingPath;
@@ -52,30 +42,13 @@ static Stream selectors() {
final ConfigurableInstanceFactory instanceFactory = DI.createInitializedFactory();
return Stream.of(
new ClassLoaderContextSelector(instanceFactory.newChildInstanceFactory()),
- new BasicContextSelector(instanceFactory.newChildInstanceFactory()),
- new AsyncLoggerContextSelector(instanceFactory.newChildInstanceFactory()),
- new BasicAsyncLoggerContextSelector(instanceFactory.newChildInstanceFactory()))
+ new BasicContextSelector(instanceFactory.newChildInstanceFactory()))
.map(Log4jContextFactory::new);
}
@ParameterizedTest(name = "reconfigure {0}")
@MethodSource("selectors")
- public void testReconfiguration(final Log4jContextFactory factory) throws Exception {
- try (final LoggerContext context = factory.getContext(FQCN, null, null, false)) {
- final Configuration defaultConfig = context.getConfiguration();
- assertThat(defaultConfig).isInstanceOf(DefaultConfiguration.class);
-
- final URI configLocation = LateConfigTest.class.getResource(CONFIG).toURI();
- final LoggerContext context1 = factory.getContext(FQCN, null, null, false, configLocation, null);
- assertThat(context1).isSameAs(context);
- assertThat(loggingPath.resolve("test-xml.log")).exists();
- final Configuration newConfig = context.getConfiguration();
- assertThat(newConfig).isInstanceOf(XmlConfiguration.class);
-
- final LoggerContext context2 = factory.getContext(FQCN, null, null, false);
- assertThat(context2).isSameAs(context);
- final Configuration sameConfig = context.getConfiguration();
- assertSame(newConfig, sameConfig, "Configuration should not have been reset");
- }
+ void reconfiguration(final Log4jContextFactory factory) throws Exception {
+ testReconfiguration(factory, loggingPath);
}
}
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
index 1266ff78043..6b0292f74db 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.java
@@ -16,75 +16,38 @@
*/
package org.apache.logging.log4j.core.appender;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.not;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.util.Arrays;
-import java.util.Collection;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.test.junit.LoggerContextRule;
-import org.apache.logging.log4j.test.junit.CleanFiles;
-import org.hamcrest.Matcher;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.RuleChain;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.test.junit.LoggerContextSource;
+import org.apache.logging.log4j.test.junit.TempLoggingDir;
+import org.junit.jupiter.api.Test;
/**
* Simple tests for both the RandomAccessFileAppender and RollingRandomAccessFileAppender.
*/
-@RunWith(Parameterized.class)
public class RandomAccessFileAppenderTest {
- @Parameterized.Parameters(name = "{0}, locationEnabled={1}, type={2}")
- public static Collection