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 contextSelectorType; final URI configUri; - Mode(final Class contextSelectorType, final String file) { + Mode(final Class 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 data() { - return Arrays.asList(new Object[][] { - {"RandomAccessFileAppenderTest", false, ".xml"}, - {"RandomAccessFileAppenderLocationTest", true, ".xml"}, - {"RollingRandomAccessFileAppenderTest", false, ".xml"}, - {"RollingRandomAccessFileAppenderLocationTest", true, ".xml"} - }); - } - - private final LoggerContextRule init; - private final CleanFiles files; - - @Rule - public final RuleChain chain; + public static final String MESSAGE = "This is a test log message brought to you by Slurm."; - private final File logFile; - private final boolean locationEnabled; - - public RandomAccessFileAppenderTest(final String testName, final boolean locationEnabled, final String type) { - this.init = new LoggerContextRule(testName + type); - this.logFile = new File("target", testName + ".log"); - this.files = new CleanFiles(this.logFile); - this.locationEnabled = locationEnabled; - this.chain = RuleChain.outerRule(files).around(init); - } + @TempLoggingDir + private static Path loggingPath; @Test - public void testRandomAccessConfiguration() throws Exception { - final Logger logger = this.init.getLogger("com.foo.Bar"); - final String message = "This is a test log message brought to you by Slurm."; - logger.info(message); - this.init.getLoggerContext().stop(); // stop async thread - - String line; - try (final BufferedReader reader = new BufferedReader(new FileReader(this.logFile))) { - line = reader.readLine(); + @LoggerContextSource + public void testRandomAccessConfiguration(final LoggerContext ctx) throws Exception { + final Logger logger = ctx.getLogger(getClass()); + logger.info(MESSAGE); + ctx.stop(); + + for (final String fileName : List.of("RandomAccessFile.log", "RollingRandomAccessFile.log")) { + final Path file = loggingPath.resolve(fileName); + assertThat(file).isNotEmptyFile(); + assertThat(Files.readAllLines(file)).hasSize(1).containsExactly(MESSAGE); } - assertNotNull(line); - assertThat(line, containsString(message)); - final Matcher containsLocationInformation = containsString("testRandomAccessConfiguration"); - final Matcher containsLocationInformationIfEnabled = - this.locationEnabled ? containsLocationInformation : not(containsLocationInformation); - assertThat(line, containsLocationInformationIfEnabled); } } diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlock.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlock.java deleted file mode 100644 index 3e6be938174..00000000000 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/AsyncLoggerClassLoadDeadlock.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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.async; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -class AsyncLoggerClassLoadDeadlock { - 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/QueueFullAsyncAppenderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java index 0e73bf8c2b1..d4d15772acd 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/async/QueueFullAsyncAppenderTest.java @@ -17,6 +17,8 @@ package org.apache.logging.log4j.core.async; import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.test.async.BlockingAppender; +import org.apache.logging.log4j.core.test.async.QueueFullAbstractTest; import org.apache.logging.log4j.core.test.junit.LoggerContextSource; import org.apache.logging.log4j.core.test.junit.Named; import org.junit.jupiter.api.Test; diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java index 623f841be89..b78741cd6c2 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/ConfigurationFactoryTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.nio.file.Path; import org.apache.logging.log4j.core.LoggerContext; +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.Tag; diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java index abdcd11303f..72fc5726fd4 100644 --- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java +++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/config/NestedLoggerConfigTest.java @@ -16,63 +16,9 @@ */ package org.apache.logging.log4j.core.config; -import static org.junit.Assert.assertEquals; - -import com.google.common.collect.ImmutableList; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.config.xml.XmlConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.apache.logging.log4j.core.test.config.AbstractNestedLoggerConfigTest; /** * Tests for LoggerConfig hierarchies. */ -@RunWith(Parameterized.class) -public class NestedLoggerConfigTest { - - @Parameterized.Parameters(name = "{0}") - public static List data() throws IOException { - return ImmutableList.of("logger-config/LoggerConfig/", "logger-config/AsyncLoggerConfig/"); - } - - private final String prefix; - - public NestedLoggerConfigTest(final String prefix) { - this.prefix = prefix; - } - - @Test - public void testInheritParentDefaultLevel() throws IOException { - final Configuration configuration = loadConfiguration(prefix + "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(prefix + "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().getClassLoader().getResourceAsStream(resourcePath)) { - final Configuration configuration = - new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in)); - configuration.initialize(); - configuration.start(); - return configuration; - } - } -} +public class NestedLoggerConfigTest extends AbstractNestedLoggerConfigTest {} diff --git a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml similarity index 58% rename from log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml index fcea9c717c9..06b2dd8035d 100644 --- a/log4j-core-test/src/test/resources/RollingRandomAccessFileAppenderTest.xml +++ b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/appender/RandomAccessFileAppenderTest.xml @@ -17,21 +17,25 @@ --> - - - %d %p %c{1.} [%t] %X{aKey} %m %location %ex%n - - - - + + + + + + - - + + - + diff --git a/log4j-core-test/src/test/resources/logger-config/LoggerConfig/default-level.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/default-level.xml similarity index 100% rename from log4j-core-test/src/test/resources/logger-config/LoggerConfig/default-level.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/default-level.xml diff --git a/log4j-core-test/src/test/resources/logger-config/LoggerConfig/inherit-level.xml b/log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/inherit-level.xml similarity index 100% rename from log4j-core-test/src/test/resources/logger-config/LoggerConfig/inherit-level.xml rename to log4j-core-test/src/test/resources/org/apache/logging/log4j/core/config/NestedLoggerConfigTest/inherit-level.xml diff --git a/log4j-core-test/src/test/resources/perf/SimplePerfTest.bat b/log4j-core-test/src/test/resources/perf/SimplePerfTest.bat deleted file mode 100644 index d6ca9ec1ba9..00000000000 --- a/log4j-core-test/src/test/resources/perf/SimplePerfTest.bat +++ /dev/null @@ -1,47 +0,0 @@ -@echo off -rem Licensed to the Apache Software Foundation (ASF) under one or more -rem contributor license agreements. See the NOTICE file distributed with -rem this work for additional information regarding copyright ownership. -rem The ASF licenses this file to You under the Apache License, Version 2.0 -rem (the "License"); you may not use this file except in compliance with -rem the License. You may obtain a copy of the License at -rem -rem http://www.apache.org/licenses/LICENSE-2.0 -rem -rem Unless required by applicable law or agreed to in writing, software -rem distributed under the License is distributed on an "AS IS" BASIS, -rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -rem See the License for the specific language governing permissions and -rem limitations under the License. - -REM reject if no arg supplied -IF %1.==. echo Usage: %0 version [core-version] & exit /b -IF %2.==. set %2=%1 - -set GC_OPTIONS= -:set GC_OPTIONS=-XX:+UnlockDiagnosticVMOptions -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -:set GC_OPTIONS=-XX:+PrintCompilation - -set LOG4J_OPTIONS= -set LOG4J_OPTIONS=-Dlog4j.configurationFile=perf-CountingNoOpAppender.xml -:set LOG4J_OPTIONS=-Dlog4j.configurationFile=perf3PlainNoLoc.xml -set LOG4J_OPTIONS=%LOG4J_OPTIONS% -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -:set LOG4J_OPTIONS=%LOG4J_OPTIONS% -Dlog4j2.enable.threadlocals=true -:set LOG4J_OPTIONS=%LOG4J_OPTIONS% -DAsyncLogger.WaitStrategy=Yield -:set LOG4J_OPTIONS=%LOG4J_OPTIONS% -DAsyncLogger.RingBufferSize=262144 - -REM Java Flight Recorder settings: %JAVA_HOME%jre\lib\jfr\default.jfc -REM Tip: set all 3 settings for "allocation-profiling-enabled" to true -set JFR_OPTIONS= -set JFR_OPTIONS=-XX:+UnlockCommercialFeatures -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -XX:+FlightRecorder -set JFR_OPTIONS=%JFR_OPTIONS% -XX:StartFlightRecording=duration=60s,filename=log4j-%1.jfr - -set CP= -set CP=log4j-api-%1.jar;log4j-core-%1.jar;disruptor-3.3.4.jar;log4j-1.2.17.jar;slf4j-api-1.7.13.jar;logback-classic-1.1.3.jar;logback-core-1.1.3.jar -set CP=%CP%;C:\Users\remko\IdeaProjects\logging-log4j2\log4j-core\target\test-classes -:set CP=%CP%;log4j-core-2.6-SNAPSHOT-tests.jar - -set MAIN=org.apache.logging.log4j.core.async.perftest.SimplePerfTest - -@echo on -java -Xms256M -Xmx256M %JFR_OPTIONS% %GC_OPTIONS% %LOG4J_OPTIONS% -cp %CP% %MAIN% diff --git a/log4j-core-test/src/test/resources/perf/SimplePerfTest.sh b/log4j-core-test/src/test/resources/perf/SimplePerfTest.sh deleted file mode 100644 index ec877a08295..00000000000 --- a/log4j-core-test/src/test/resources/perf/SimplePerfTest.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh -# -# -# 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. -# -if [ $# -eq 0 ]; then - echo Usage: $0 api-version core-version - exit 1 -fi - -DIR=$HOME -NOW=$(date +%Y%m%d-%H%M%S) - -GC_OPTIONS="-XX:+UnlockDiagnosticVMOptions -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps" -GC_OPTIONS="${GC_OPTIONS} -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime" -GC_OPTIONS="${GC_OPTIONS} -XX:+PrintGCCause -Xloggc:$DIR/gc-$NOW.log" -#GC_OPTIONS="${GC_OPTIONS} -XX:+PrintSafepointStatistics -XX:+LogVMOutput -XX:LogFile=$DIR/safepoint$NOW.log" -GC_OPTIONS= - -# Needs -XX:+UnlockDiagnosticVMOptions (as first VM arg) -#VM_OPTIONS="-XX:+PrintCompilation -XX:+PrintInlining" - -LOG4J_OPTIONS="-Dlog4j.configurationFile=perf-CountingNoOpAppender.xml" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -DAsyncLogger.WaitStrategy=Block" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -Dlog4j.format.msg.async=true" -export LOG4J_OPTIONS - -CP="log4j-api-${1}.jar:log4j-core-${2}.jar:disruptor-3.3.4.jar" -CP="${CP}:log4j-core-2.6-SNAPSHOT-tests.jar" -#CP="${CP}:${HOME}/Documents/log4j/log4j-core/target/test-classes" -export CP - -export MEM_OPTIONS="-Xms128m -Xmx128m" -export MAIN="org.apache.logging.log4j.core.async.perftest.SimplePerfTest" - -#PERF_OPTIONS="-e cycles,instructions,cache-references,cache-misses,branches,branch-misses,L1-dcache-loads,L1-dcache-load-misses,dTLB-loads,dTLB-load-misses" -PERF_OPTIONS= -#perf stat ${PERF_OPTIONS} java ${MEM_OPTIONS} ${GC_OPTIONS} ${VM_OPTIONS} ${LOG4J_OPTIONS} -cp "${CP}" ${MAIN} - -java ${MEM_OPTIONS} ${GC_OPTIONS} ${VM_OPTIONS} ${LOG4J_OPTIONS} -cp "${CP}" ${MAIN} diff --git a/log4j-core-test/src/test/resources/perf/runResponseTm.sh b/log4j-core-test/src/test/resources/perf/runResponseTm.sh deleted file mode 100644 index 2860dcd9be8..00000000000 --- a/log4j-core-test/src/test/resources/perf/runResponseTm.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh -# -# -# 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. -# - -NOW=$(date +%Y%m%d-%H%M%S) - -GC_OPTIONS="-XX:+UnlockDiagnosticVMOptions -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime" -#GC_OPTIONS="${GC_OPTIONS} -XX:GuaranteedSafepointInterval=500000" -GC_OPTIONS="${GC_OPTIONS} -XX:+PrintGCCause -XX:+PrintSafepointStatistics -XX:+LogVMOutput -XX:LogFile=safepoint$NOW.log" -COMPILE_OPTIONS="-XX:CompileCommand=dontinline,org.apache.logging.log4j.core.async.perftest.NoOpIdleStrategy::idle" - -#VM_OPTIONS="-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining" - -LOG4J_OPTIONS= -#LOG4J_OPTIONS="-Dlog4j.configurationFile=perf-CountingNoOpAppender.xml" -#LOG4J_OPTIONS="-Dlog4j.configurationFile=perf3PlainNoLoc.xml" -#LOG4J_OPTIONS="-Dlog4j.configurationFile=perf7MixedNoLoc.xml" -LOG4J_OPTIONS="-Dlog4j.configurationFile=perf5AsyncApndNoLoc.xml" - -#LOG4J_OPTIONS="-Dlog4j.configuration=perf-log4j12.xml" -#LOG4J_OPTIONS="-Dlog4j.configuration=perf-log4j12-async.xml" -#LOG4J_OPTIONS="-Dlogback.configurationFile=perf-logback-async.xml" -#LOG4J_OPTIONS="-Dlogback.configurationFile=perf-logback.xml" - -#LOG4J_OPTIONS="${LOG4J_OPTIONS} -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -Dlog4j2.enable.direct.encoders=true" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -DAsyncLogger.WaitStrategy=busySpin" -LOG4J_OPTIONS="${LOG4J_OPTIONS} -DAsyncLoggerConfig.WaitStrategy=busySpin" -#LOG4J_OPTIONS="${LOG4J_OPTIONS} -Dlog4j.format.msg.async=true" -export LOG4J_OPTIONS - -CP=".:HdrHistogram-2.1.8.jar:disruptor-3.3.4.jar:log4j-1.2.17.jar:slf4j-api-1.7.21.jar:slf4j-ext-1.7.21.jar:logback-core-1.1.7.jar:logback-classic-1.1.7.jar:log4j-api-2.6-SNAPSHOT.jar:log4j-core-2.6-SNAPSHOT.jar:log4j-core-2.6-SNAPSHOT-tests.jar" - -RUNNER=RunLog4j2 -RESULTDIR=ApndLog4j2 -java -Xms1G -Xmx1G $GC_OPTIONS $COMPILE_OPTIONS $VM_OPTIONS $JFR_OPTIONS $LOG4J_OPTIONS -cp $CP org.apache.logging.log4j.core.async.perftest.ResponseTimeTest 1 10000 $RUNNER -java -Xms1G -Xmx1G $GC_OPTIONS $COMPILE_OPTIONS $VM_OPTIONS $JFR_OPTIONS $LOG4J_OPTIONS -cp $CP org.apache.logging.log4j.core.async.perftest.ResponseTimeTest 2 5000 $RUNNER -java -Xms1G -Xmx1G $GC_OPTIONS $COMPILE_OPTIONS $VM_OPTIONS $JFR_OPTIONS $LOG4J_OPTIONS -cp $CP org.apache.logging.log4j.core.async.perftest.ResponseTimeTest 4 2500 $RUNNER -mkdir async$RESULTDIR-10k -mv *k? async$RESULTDIR-10k -mv nohup.out async$RESULTDIR-10k -mv safepoint$NOW.log async$RESULTDIR-10k - - diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml index cdbbeca83c3..e676d00b879 100644 --- a/log4j-core/pom.xml +++ b/log4j-core/pom.xml @@ -92,12 +92,6 @@ disruptor true - - - com.lmax - disruptor - true - org.fusesource.jansi diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java index 9a2decdd0f7..ea6b92983e8 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java @@ -939,4 +939,11 @@ public String toString() { protected Logger newInstance(final LoggerContext ctx, final String name, final MessageFactory messageFactory) { return new Logger(ctx, name, messageFactory); } + + /** + * If {@code true} loggers will include location by default. + */ + public boolean includeLocation() { + return true; + } } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java index ee7d7d8834e..f820bee263c 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java @@ -173,7 +173,17 @@ public void append(final LogEvent logEvent) { } else { // delegate to the event router (which may discard, enqueue and block, or log in current thread) final EventRoute route = asyncQueueFullPolicy.getRoute(dispatcher.getId(), memento.getLevel()); - route.logMessage(this, memento); + switch (route) { + case DISCARD: + break; + case ENQUEUE: + logMessageInBackgroundThread(memento); + break; + case SYNCHRONOUS: + logMessageInCurrentThread(memento); + break; + default: + } } } else { error("Appender " + getName() + " is unable to write primary appenders. queue is full"); diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java index 2c6d50d4e99..eb844022ef4 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/EventRoute.java @@ -16,12 +16,6 @@ */ package org.apache.logging.log4j.core.async; -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AsyncAppender; -import org.apache.logging.log4j.message.Message; - /** * Enumeration over the different destinations where a log event can be sent. * @@ -35,86 +29,15 @@ public enum EventRoute { /** * Enqueues the event for asynchronous logging in the background thread. */ - ENQUEUE { - @Override - public void logMessage( - final AsyncLogger asyncLogger, - final String fqcn, - final Level level, - final Marker marker, - final Message message, - final Throwable thrown) {} - - @Override - public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { - asyncLoggerConfig.logInBackgroundThread(event); - } - - @Override - public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) { - asyncAppender.logMessageInBackgroundThread(logEvent); - } - }, + ENQUEUE, /** * Logs the event synchronously: sends the event directly to the appender (in the current thread). * WARNING: This may result in lines logged out of order as synchronous events may be persisted before * earlier events, even from the same thread, which wait in the queue. */ - SYNCHRONOUS { - @Override - public void logMessage( - final AsyncLogger asyncLogger, - final String fqcn, - final Level level, - final Marker marker, - final Message message, - final Throwable thrown) {} - - @Override - public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { - asyncLoggerConfig.logToAsyncLoggerConfigsOnCurrentThread(event); - } - - @Override - public void logMessage(final AsyncAppender asyncAppender, final LogEvent logEvent) { - asyncAppender.logMessageInCurrentThread(logEvent); - } - }, + SYNCHRONOUS, /** * Discards the event (so it is not logged at all). */ - DISCARD { - @Override - public void logMessage( - final AsyncLogger asyncLogger, - final String fqcn, - final Level level, - final Marker marker, - final Message message, - final Throwable thrown) { - // do nothing: drop the event - } - - @Override - public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { - // do nothing: drop the event - } - - @Override - public void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent) { - // do nothing: drop the event - } - }; - - public abstract void logMessage( - final AsyncLogger asyncLogger, - final String fqcn, - final Level level, - final Marker marker, - final Message message, - final Throwable thrown); - - public abstract void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event); - - public abstract void logMessage(final AsyncAppender asyncAppender, final LogEvent coreEvent); + DISCARD; } diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java index 9859c0c9443..ab9930c633b 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Marker; @@ -27,9 +28,6 @@ import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.async.AsyncLoggerConfig; -import org.apache.logging.log4j.core.async.AsyncLoggerContext; -import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.config.plugins.PluginConfiguration; import org.apache.logging.log4j.core.filter.AbstractFilterable; import org.apache.logging.log4j.core.impl.Log4jLogEvent; @@ -495,7 +493,7 @@ public void log( final LogEvent logEvent = logEventFactory.createEvent(loggerName, marker, fqcn, location(fqcn), level, data, props, t); try { - log(logEvent, LoggerConfigPredicate.ALL); + log(logEvent, null); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) logEventFactory.recycle(logEvent); @@ -530,7 +528,7 @@ public void log( final LogEvent logEvent = logEventFactory.createEvent(loggerName, marker, fqcn, location, level, data, props, t); try { - log(logEvent, LoggerConfigPredicate.ALL); + log(logEvent, null); } finally { // LOG4J2-1583 prevent scrambled logs when logging calls are nested (logging in toString()) logEventFactory.recycle(logEvent); @@ -584,17 +582,17 @@ private List getPropertiesWithLookups( * @param event The log event. */ public void log(final LogEvent event) { - log(event, LoggerConfigPredicate.ALL); + log(event, null); } /** * Logs an event. * * @param event The log event. - * @param predicate predicate for which LoggerConfig instances to append to. A - * {@literal null} value is equivalent to a true predicate. + * @param predicate predicate for which LoggerConfig instances to append to. + * Use a {@literal null} value instead of a true predicate. */ - protected void log(final LogEvent event, final LoggerConfigPredicate predicate) { + protected void log(final LogEvent event, final Predicate predicate) { if (!isFiltered(event)) { processLogEvent(event, predicate); } @@ -614,12 +612,12 @@ public ReliabilityStrategy getReliabilityStrategy() { * Logs an event, bypassing filters. * * @param event The log event. - * @param predicate predicate for which LoggerConfig instances to append to. A - * {@literal null} value is equivalent to a true predicate. + * @param predicate predicate for which LoggerConfig instances to append to. + * Use a {@literal null} value instead of a true predicate. */ - protected void processLogEvent(final LogEvent event, final LoggerConfigPredicate predicate) { + protected void processLogEvent(final LogEvent event, final Predicate predicate) { event.setIncludeLocation(isIncludeLocation()); - if (predicate == null || predicate.allow(this)) { + if (predicate == null || predicate.test(this)) { callAppenders(event); } logParent(event, predicate); @@ -649,7 +647,7 @@ public boolean requiresLocation() { return false; } - private void logParent(final LogEvent event, final LoggerConfigPredicate predicate) { + private void logParent(final LogEvent event, final Predicate predicate) { if (additive && parent != null) { parent.log(event, predicate); } @@ -674,14 +672,11 @@ public String toString() { protected static boolean includeLocation( final String includeLocationConfigValue, final Configuration configuration) { if (includeLocationConfigValue == null) { - LoggerContext context = null; if (configuration != null) { - context = configuration.getLoggerContext(); - } - if (context != null) { - return !(context instanceof AsyncLoggerContext); + final LoggerContext context = configuration.getLoggerContext(); + return context != null ? context.includeLocation() : false; } else { - return !AsyncLoggerContextSelector.isSelected(); + return false; } } return Boolean.parseBoolean(includeLocationConfigValue); @@ -860,27 +855,4 @@ protected static class LevelAndRefs { public Level level; public List refs; } - - protected enum LoggerConfigPredicate { - ALL() { - @Override - boolean allow(final LoggerConfig config) { - return true; - } - }, - ASYNCHRONOUS_ONLY() { - @Override - boolean allow(final LoggerConfig config) { - return config instanceof AsyncLoggerConfig; - } - }, - SYNCHRONOUS_ONLY() { - @Override - boolean allow(final LoggerConfig config) { - return !ASYNCHRONOUS_ONLY.allow(config); - } - }; - - abstract boolean allow(LoggerConfig config); - } } diff --git a/log4j-csv/pom.xml b/log4j-csv/pom.xml index d9efac8623b..9556eb32a23 100644 --- a/log4j-csv/pom.xml +++ b/log4j-csv/pom.xml @@ -53,6 +53,11 @@ log4j-api-test test + + org.apache.logging.log4j + log4j-async-logger + test + org.apache.logging.log4j log4j-core-test diff --git a/log4j-csv/src/test/java/org/apache/logging/log4j/csv/layout/CsvParameterLayoutAllAsyncTest.java b/log4j-csv/src/test/java/org/apache/logging/log4j/csv/layout/CsvParameterLayoutAllAsyncTest.java index 64cff2cfe48..e57d2c99c87 100644 --- a/log4j-csv/src/test/java/org/apache/logging/log4j/csv/layout/CsvParameterLayoutAllAsyncTest.java +++ b/log4j-csv/src/test/java/org/apache/logging/log4j/csv/layout/CsvParameterLayoutAllAsyncTest.java @@ -18,8 +18,8 @@ import org.apache.commons.csv.CSVFormat; import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.async.logger.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.Logger; -import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.impl.Log4jPropertyKey; import org.apache.logging.log4j.core.test.categories.Layouts; import org.apache.logging.log4j.util.Strings; diff --git a/log4j-gc-test/pom.xml b/log4j-gc-test/pom.xml index 66a32be6403..8d10ca0391c 100644 --- a/log4j-gc-test/pom.xml +++ b/log4j-gc-test/pom.xml @@ -32,6 +32,11 @@ true + + org.apache.logging.log4j + log4j-async-logger + test + org.apache.logging.log4j log4j-core diff --git a/log4j-gc-test/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsyncLoggingTest.java b/log4j-gc-test/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsyncLoggingTest.java index 7b49932dcc0..ac19e9e3449 100644 --- a/log4j-gc-test/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsyncLoggingTest.java +++ b/log4j-gc-test/src/test/java/org/apache/logging/log4j/gctests/GcFreeAsyncLoggingTest.java @@ -16,7 +16,7 @@ */ package org.apache.logging.log4j.gctests; -import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; +import org.apache.logging.log4j.async.logger.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.impl.Log4jPropertyKey; import org.apache.logging.log4j.spi.LoggingSystemProperty; import org.junit.jupiter.api.Tag; diff --git a/log4j-jul/pom.xml b/log4j-jul/pom.xml index bf99f999161..5fb2704a4c5 100644 --- a/log4j-jul/pom.xml +++ b/log4j-jul/pom.xml @@ -71,6 +71,11 @@ junit test + + org.apache.logging.log4j + log4j-async-logger + test + org.apache.logging.log4j log4j-core-test @@ -122,8 +127,6 @@ test - ${log4j.skip.test1} - ${log4j.skip.test2} Log4jBridgeHandlerTest.java diff --git a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/test/AsyncLoggerThreadsTest.java b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/test/AsyncLoggerThreadsTest.java index 3abe1f97432..aa36a07de4f 100644 --- a/log4j-jul/src/test/java/org/apache/logging/log4j/jul/test/AsyncLoggerThreadsTest.java +++ b/log4j-jul/src/test/java/org/apache/logging/log4j/jul/test/AsyncLoggerThreadsTest.java @@ -21,7 +21,7 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; +import org.apache.logging.log4j.async.logger.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.impl.Log4jPropertyKey; import org.apache.logging.log4j.core.test.categories.AsyncLoggers; import org.junit.AfterClass; diff --git a/log4j-perf-test/pom.xml b/log4j-perf-test/pom.xml index 92e055ea94d..3892cddbe1e 100644 --- a/log4j-perf-test/pom.xml +++ b/log4j-perf-test/pom.xml @@ -49,6 +49,10 @@ org.apache.logging.log4j log4j-api + + org.apache.logging.log4j + log4j-async-logger + org.apache.logging.log4j log4j-core diff --git a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java index 2dd0bcfa653..54f7c3d6dba 100644 --- a/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java +++ b/log4j-perf-test/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderThrowableBenchmark.java @@ -24,8 +24,8 @@ import java.util.logging.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.core.async.AsyncLoggerContext; -import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; +import org.apache.logging.log4j.async.logger.AsyncLoggerContext; +import org.apache.logging.log4j.async.logger.AsyncLoggerContextSelector; import org.apache.logging.log4j.core.impl.Log4jPropertyKey; import org.apache.logging.log4j.spi.LoggingSystemProperty; import org.openjdk.jmh.annotations.Benchmark; diff --git a/log4j-script/src/test/java/org/apache/logging/log4j/script/config/builder/ConfigurationAssemblerTest.java b/log4j-script/src/test/java/org/apache/logging/log4j/script/config/builder/ConfigurationAssemblerTest.java index b0f9dce0e76..5e2bc26ad66 100644 --- a/log4j-script/src/test/java/org/apache/logging/log4j/script/config/builder/ConfigurationAssemblerTest.java +++ b/log4j-script/src/test/java/org/apache/logging/log4j/script/config/builder/ConfigurationAssemblerTest.java @@ -47,19 +47,11 @@ public class ConfigurationAssemblerTest { @Test public void testBuildConfiguration() throws Exception { - try { - System.setProperty( - Log4jPropertyKey.CONTEXT_SELECTOR_CLASS_NAME.getSystemKey(), - "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"); - final ConfigurationBuilder builder = - ConfigurationBuilderFactory.newConfigurationBuilder(); - CustomConfigurationFactory.addTestFixtures("config name", builder); - final Configuration configuration = builder.build(); - try (final LoggerContext ctx = Configurator.initialize(configuration)) { - validate(configuration); - } - } finally { - System.getProperties().remove(Log4jPropertyKey.CONTEXT_SELECTOR_CLASS_NAME.getSystemKey()); + final ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); + CustomConfigurationFactory.addTestFixtures("config name", builder); + final Configuration configuration = builder.build(); + try (final LoggerContext ctx = Configurator.initialize(configuration)) { + validate(configuration); } } @@ -69,13 +61,9 @@ public void testCustomConfigurationFactory() throws Exception { System.setProperty( Log4jPropertyKey.CONFIG_CONFIGURATION_FACTORY_CLASS_NAME.getSystemKey(), "org.apache.logging.log4j.script.config.builder.CustomConfigurationFactory"); - System.setProperty( - Log4jPropertyKey.CONTEXT_SELECTOR_CLASS_NAME.getSystemKey(), - "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"); final Configuration config = ((LoggerContext) LogManager.getContext(false)).getConfiguration(); validate(config); } finally { - System.getProperties().remove(Log4jPropertyKey.CONTEXT_SELECTOR_CLASS_NAME.getSystemKey()); System.getProperties().remove(Log4jPropertyKey.CONFIG_CONFIGURATION_FACTORY_CLASS_NAME.getSystemKey()); } } diff --git a/pom.xml b/pom.xml index 26b3c44413e..f4fd649db79 100644 --- a/pom.xml +++ b/pom.xml @@ -236,6 +236,7 @@ log4j-api log4j-api-test log4j-appserver + log4j-async-logger log4j-config-jackson log4j-config-properties log4j-config-yaml @@ -374,6 +375,12 @@ ${project.version} + + org.apache.logging.log4j + log4j-async-logger + ${project.version} + + org.apache.logging.log4j log4j-config-jackson diff --git a/src/changelog/.3.x.x/create_async_logger.xml b/src/changelog/.3.x.x/create_async_logger.xml new file mode 100644 index 00000000000..bb0f561a780 --- /dev/null +++ b/src/changelog/.3.x.x/create_async_logger.xml @@ -0,0 +1,9 @@ + + + + Split off async logger support into a new `log4j-async-logger` module. + +