Skip to content

Commit

Permalink
Evaluate StatusLogger.getLogger lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
ppkarwasz committed Mar 25, 2024
1 parent 0396436 commit 21b283f
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.status.StatusLogger;
import org.apache.logging.log4j.test.TestProperties;
import org.junit.jupiter.api.extension.BeforeAllCallback;
Expand All @@ -45,16 +44,14 @@

public class TempLoggingDirectory implements BeforeAllCallback, BeforeEachCallback, ParameterResolver {

private static final Logger LOGGER = StatusLogger.getLogger();

@Override
public void beforeAll(ExtensionContext context) throws Exception {
final List<Field> fields = AnnotationSupport.findAnnotatedFields(
context.getRequiredTestClass(), TempLoggingDir.class, ModifierSupport::isStatic);
Path loggingPath = null;
for (final Field field : fields) {
if (loggingPath != null) {
LOGGER.warn("Multiple fields with @TempLoggingDir annotation are not supported.");
StatusLogger.getLogger().warn("Multiple fields with @TempLoggingDir annotation are not supported.");
} else {
final CleanupMode cleanup = determineCleanupMode(field);
loggingPath = createLoggingPath(context, cleanup).getPath();
Expand All @@ -81,7 +78,7 @@ public void beforeEach(ExtensionContext context) throws Exception {
final Object instance = context.getRequiredTestInstance();
for (final Field field : fields) {
if (loggingPath != null) {
LOGGER.warn("Multiple fields with @TempLoggingDir annotation are not supported.");
StatusLogger.getLogger().warn("Multiple fields with @TempLoggingDir annotation are not supported.");
} else {
final CleanupMode cleanup = determineCleanupMode(field);
loggingPath = createLoggingPath(context, cleanup).getPath();
Expand Down Expand Up @@ -180,7 +177,7 @@ public void close() throws IOException {
|| (cleanupMode == ON_SUCCESS
&& contexts.keySet().stream().anyMatch(context -> context.getExecutionException()
.isPresent()))) {
LOGGER.debug("Skipping cleanup of directory {}.", path);
StatusLogger.getLogger().debug("Skipping cleanup of directory {}.", path);
return;
}
DirectoryCleaner.deleteDirectory(path);
Expand Down

0 comments on commit 21b283f

Please sign in to comment.