You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2023/09/07 13:45:14 UTC
[logging-log4j2] branch 2.x updated: Add a default location for @LoggerContextSource
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new f68d7cabb3 Add a default location for @LoggerContextSource
f68d7cabb3 is described below
commit f68d7cabb32d68fea1c0eae390bde26f4ef6940f
Author: Piotr P. Karwasz <pi...@karwasz.org>
AuthorDate: Thu Sep 7 15:44:35 2023 +0200
Add a default location for @LoggerContextSource
Our integration tests use a lot of configurations, which are now in a
flat folder. Moving them to a tree structure will add some order to the
repo.
---
.../logging/log4j/core/test/junit/LoggerContextResolver.java | 11 ++++++++++-
.../logging/log4j/core/test/junit/LoggerContextSource.java | 7 ++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
index 5ba43881e5..a51d73ee47 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextResolver.java
@@ -137,12 +137,21 @@ class LoggerContextResolver extends TypeBasedParameterResolver<LoggerContext> im
private LoggerContextConfig(final LoggerContextSource source, final ExtensionContext extensionContext) {
final String displayName = extensionContext.getDisplayName();
final ClassLoader classLoader = extensionContext.getRequiredTestClass().getClassLoader();
- context = Configurator.initialize(displayName, classLoader, source.value());
+ context = Configurator.initialize(displayName, classLoader, getConfigLocation(source, extensionContext));
reconfigurationPolicy = source.reconfigure();
shutdownTimeout = source.timeout();
unit = source.unit();
}
+ private static String getConfigLocation(final LoggerContextSource source,
+ final ExtensionContext extensionContext) {
+ final String value = source.value();
+ if (value.isEmpty()) {
+ return extensionContext.getRequiredTestClass().getName().replaceAll("[.$]", "/") + ".xml";
+ }
+ return value;
+ }
+
@Override
public LoggerContext getLoggerContext() {
return context;
diff --git a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextSource.java b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextSource.java
index 0fc72f723b..a7294b6011 100644
--- a/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextSource.java
+++ b/log4j-core-test/src/main/java/org/apache/logging/log4j/core/test/junit/LoggerContextSource.java
@@ -58,8 +58,13 @@ import org.junit.jupiter.api.extension.ExtendWith;
public @interface LoggerContextSource {
/**
* Specifies the name of the configuration file to use for the annotated test.
+ * <p>
+ * Defaults to the fully qualified name of the test class with '.xml' appended.
+ * E.g. this class would have a default of
+ * {@code org/apache/logging/log4j/core/test/junit/LoggerContextSource.xml}.
+ * </p>
*/
- String value();
+ String value() default "";
/**
* Specifies when to {@linkplain LoggerContext#reconfigure() reconfigure} the logging system.