From bbb4e2e11c1962a6eb627cc6b72b07b5b314c73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Tue, 5 Mar 2024 18:47:16 +0100 Subject: [PATCH] Improve logging for IO utils and add thread info in build logs * Add additional logging on IO utils methods to detect potential issues with concurrent build steps. * Print thread information for DEBUG or TRACE log messages in build logs. --- .../src/main/java/io/quarkus/maven/MojoLogger.java | 7 ++++++- .../main/java/io/quarkus/bootstrap/util/IoUtils.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/MojoLogger.java b/devtools/maven/src/main/java/io/quarkus/maven/MojoLogger.java index 8870379dc919f..45ea2a7b34622 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/MojoLogger.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/MojoLogger.java @@ -91,7 +91,12 @@ public boolean isEnabled(final Level level) { void doActualLog(final Log log, final Level level, final String message, final Throwable thrown) { final MessageBuilder buffer = MessageUtils.buffer(); // style options are limited unless we crack into jansi ourselves - buffer.strong("[").project(name).strong("]").a(" ").a(message); + if (Level.DEBUG.compareTo(level) <= 0) { + buffer.strong("[").project(name).strong("]").a(" ").a("(").a(Thread.currentThread().getName()).a(")").a(" ") + .a(message); + } else { + buffer.strong("[").project(name).strong("]").a(" ").a(message); + } if (thrown != null) { switch (level) { case FATAL: diff --git a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/util/IoUtils.java b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/util/IoUtils.java index ba28f563ad583..0c4006fc3dc74 100644 --- a/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/util/IoUtils.java +++ b/independent-projects/bootstrap/app-model/src/main/java/io/quarkus/bootstrap/util/IoUtils.java @@ -21,6 +21,8 @@ import java.util.Objects; import java.util.UUID; +import org.jboss.logging.Logger; + /** * * @author Alexey Loubyansky @@ -31,6 +33,8 @@ public class IoUtils { private static final Path TMP_DIR = Paths.get(PropertyUtils.getProperty("java.io.tmpdir")); + private static final Logger log = Logger.getLogger(IoUtils.class); + private static void failedToMkDir(final Path dir) { throw new IllegalStateException("Failed to create directory " + dir); } @@ -57,6 +61,7 @@ public static Path mkdirs(Path dir) { } public static void recursiveDelete(Path root) { + log.debugf("Recursively delete directory %s", root); if (root == null || !Files.exists(root)) { return; } @@ -68,6 +73,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) try { Files.delete(file); } catch (IOException ex) { + log.debugf(ex, "Unable to delete file " + file); } return FileVisitResult.CONTINUE; } @@ -79,6 +85,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) try { Files.delete(dir); } catch (IOException ex) { + log.debugf(ex, "Unable to delete directory " + dir); } return FileVisitResult.CONTINUE; } else { @@ -88,6 +95,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) } }); } catch (IOException e) { + log.debugf(e, "Error recursively deleting directory"); } } @@ -98,19 +106,23 @@ public FileVisitResult postVisitDirectory(Path dir, IOException e) * @throws IOException in case of a failure */ public static void createOrEmptyDir(Path dir) throws IOException { + log.debugf("Create or empty directory %s", dir); Objects.requireNonNull(dir); if (!Files.exists(dir)) { + log.debugf("Directory %s does not exist, create directories", dir); Files.createDirectories(dir); return; } if (!Files.isDirectory(dir)) { throw new IllegalArgumentException(dir + " is not a directory"); } + log.debugf("Iterate over contents of %s to delete its contents", dir); try (DirectoryStream stream = Files.newDirectoryStream(dir)) { for (Path p : stream) { if (Files.isDirectory(p)) { recursiveDelete(p); } else { + log.debugf("Delete file %s", p); Files.delete(p); } }