You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "vy (via GitHub)" <gi...@apache.org> on 2024/10/09 11:32:01 UTC

Re: [PR] Use a random `${test:logging.path}` (logging-log4j2)

vy commented on code in PR #2954:
URL: https://github.com/apache/logging-log4j2/pull/2954#discussion_r1793353005


##########
log4j-api-test/src/main/java/org/apache/logging/log4j/test/junit/TempLoggingDirectory.java:
##########
@@ -135,6 +132,29 @@ private PathHolder createLoggingPath(final ExtensionContext context, final Clean
         return holder;
     }
 
+    private Path determinePerClassPath(ExtensionContext context) {
+        // Check if the parent context already created a folder
+        PathHolder holder = ExtensionContextAnchor.getAttribute(PathHolder.class, PathHolder.class, context);
+        if (holder == null) {
+            try {
+                // Create temporary per-class directory
+                final String baseDir = System.getProperty("basedir");
+                final Path basePath = (baseDir != null ? Paths.get(baseDir, "target") : Paths.get(".")).resolve("logs");
+                final Class<?> clazz = context.getRequiredTestClass();
+                final Package pkg = clazz.getPackage();
+                final String dir =
+                        pkg.getName().replaceAll("[.$]", File.separatorChar == '\\' ? "\\\\" : File.separator);
+                // Create a temporary directory that uses the simple class name as prefix
+                Path packagePath = basePath.resolve(dir);
+                Files.createDirectories(packagePath);
+                return Files.createTempDirectory(packagePath, clazz.getSimpleName());

Review Comment:
   `Files.createTempDirectory()` already takes care of the distinctiveness – I just want to be able to spot the last effective folder. I don't see how adding just a counter helps, since counters get reset at reruns. Am I missing something?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org