Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging for IO utils and add thread info in build logs #39214

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
galderz committed Mar 6, 2024
commit bbb4e2e11c1962a6eb627cc6b72b07b5b314c73f
Original file line number Diff line number Diff line change
@@ -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:
Original file line number Diff line number Diff line change
@@ -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<Path> stream = Files.newDirectoryStream(dir)) {
for (Path p : stream) {
if (Files.isDirectory(p)) {
recursiveDelete(p);
} else {
log.debugf("Delete file %s", p);
Files.delete(p);
}
}