Migrating to fluent logging (green).
I did some minor clean-ups of the resulting logging statements (mostly moving/adding exceptions as causes that were missed), and a few other drive-bys.
PiperOrigin-RevId: 306265560
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
index 6e7b367..5dfe942 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java
@@ -17,6 +17,7 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.actions.SpawnResult.MetadataLog;
import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEvent.LocalFile.LocalFileType;
@@ -33,15 +34,13 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.Collection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* This event is fired during the build, when an action is executed. It contains information about
* the action: the Action itself, and the output file names its stdout and stderr are recorded in.
*/
public class ActionExecutedEvent implements BuildEventWithConfiguration, ProgressLike {
- private static final Logger logger = Logger.getLogger(ActionExecutedEvent.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private final PathFragment actionId;
private final Action action;
@@ -225,7 +224,7 @@
}
} catch (CommandLineExpansionException e) {
// Command-line not available, so just not report it
- logger.log(Level.INFO, "Could no compute commandline of reported action", e);
+ logger.atInfo().withCause(e).log("Could not compute commandline of reported action");
}
return GenericBuildEvent.protoChaining(this).setAction(actionBuilder.build()).build();
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BUILD b/src/main/java/com/google/devtools/build/lib/actions/BUILD
index 3d579c4..3049ad0 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/actions/BUILD
@@ -74,6 +74,7 @@
"//src/main/protobuf:extra_actions_base_java_proto",
"//src/main/protobuf:failure_details_java_proto",
"//third_party:auto_value",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FilesetManifest.java b/src/main/java/com/google/devtools/build/lib/actions/FilesetManifest.java
index 3d457db..f60f0ed 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FilesetManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FilesetManifest.java
@@ -15,6 +15,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.io.IOException;
import java.util.Collections;
@@ -23,14 +24,13 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
* Representation of a Fileset manifest.
*/
public final class FilesetManifest {
- private static final Logger logger = Logger.getLogger(FilesetManifest.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* Mode that determines how to handle relative target paths.
@@ -122,26 +122,22 @@
} while (++traversals <= MAX_SYMLINK_TRAVERSALS && actual != null && seen.add(actual));
if (traversals >= MAX_SYMLINK_TRAVERSALS) {
- logger.warning(
- "Symlink "
- + location
- + " is part of a chain of length at least "
- + traversals
- + " which exceeds Blaze's maximum allowable symlink chain length");
+ logger.atWarning().log(
+ "Symlink %s is part of a chain of length at least %d"
+ + " which exceeds Blaze's maximum allowable symlink chain length",
+ location, traversals);
} else if (actual != null) {
// TODO(b/113128395): throw here.
- logger.warning("Symlink " + location + " forms a symlink cycle: " + seen);
+ logger.atWarning().log("Symlink %s forms a symlink cycle: %s", location, seen);
} else if (!entries.containsKey(actualLocation)) {
// We've found a relative symlink that points out of the fileset. We should really always
// throw here, but current behavior is that we tolerate such symlinks when they occur in
// runfiles, which is the only time this code is hit.
// TODO(b/113128395): throw here.
- logger.warning(
- "Symlink "
- + location
- + " (transitively) points to "
- + actualLocation
- + " that is not in this fileset (or was pruned because of a cycle)");
+ logger.atWarning().log(
+ "Symlink %s (transitively) points to %s"
+ + " that is not in this fileset (or was pruned because of a cycle)",
+ location, actualLocation);
} else {
// We have successfully resolved the symlink.
entries.put(location, entries.get(actualLocation));
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD b/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD
index 9d0a032..5ccbe82 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/BUILD
@@ -32,6 +32,7 @@
"//src/main/java/com/google/devtools/build/lib/util:exit_code",
"//third_party:auto_value",
"//third_party:error_prone_annotations",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
index df5071d..b1d087d 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
@@ -19,6 +19,7 @@
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.devtools.build.lib.bugreport.BugReport;
@@ -39,8 +40,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@@ -51,7 +50,7 @@
@SuppressWarnings("unchecked")
@AutoCodec
public final class NestedSet<E> {
- private static final Logger logger = Logger.getLogger(NestedSet.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* Order and size of set packed into one int.
@@ -454,7 +453,7 @@
try {
return Arrays.toString(Futures.getDone(future));
} catch (ExecutionException e) {
- logger.log(Level.SEVERE, "Error getting " + future, e);
+ logger.atSevere().withCause(e).log("Error getting %s", future);
// Don't rethrow, since we may be in the process of trying to construct an error message.
return "Future " + future + " with error: " + e.getCause().getMessage();
}
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetStore.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetStore.java
index fcd6230..83c2573 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetStore.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSetStore.java
@@ -19,6 +19,7 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableList;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.hash.Hashing;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -40,7 +41,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@@ -69,7 +69,7 @@
*/
public class NestedSetStore {
- private static final Logger logger = Logger.getLogger(NestedSetStore.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private static final Duration FETCH_FROM_STORAGE_LOGGING_THRESHOLD = Duration.ofSeconds(5);
/** Stores fingerprint -> NestedSet associations. */
@@ -375,10 +375,9 @@
bytes -> {
Duration fetchDuration = fetchStopwatch.elapsed();
if (FETCH_FROM_STORAGE_LOGGING_THRESHOLD.compareTo(fetchDuration) < 0) {
- logger.info(
- String.format(
- "NestedSet fetch took: %dms, size: %dB",
- fetchDuration.toMillis(), bytes.length));
+ logger.atInfo().log(
+ "NestedSet fetch took: %dms, size: %dB",
+ fetchDuration.toMillis(), bytes.length);
}
CodedInputStream codedIn = CodedInputStream.newInstance(bytes);
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java b/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
index 3abc2bf..fa91564 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/AbstractQueueVisitor.java
@@ -17,6 +17,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
@@ -35,8 +36,6 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/** A {@link QuiescingExecutor} implementation that wraps an {@link ExecutorService}. */
public class AbstractQueueVisitor implements QuiescingExecutor {
@@ -131,7 +130,7 @@
private final ErrorClassifier errorClassifier;
- private static final Logger logger = Logger.getLogger(AbstractQueueVisitor.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* Default function for constructing {@link ThreadPoolExecutor}s. The {@link ThreadPoolExecutor}s
@@ -314,7 +313,7 @@
case AS_CRITICAL_AS_POSSIBLE:
case CRITICAL_AND_LOG:
critical = true;
- logger.log(Level.WARNING, "Found critical error in queue visitor", e);
+ logger.atWarning().withCause(e).log("Found critical error in queue visitor");
break;
case CRITICAL:
critical = true;
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/BUILD b/src/main/java/com/google/devtools/build/lib/concurrent/BUILD
index 21a940a..b370069 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/BUILD
@@ -13,6 +13,7 @@
name = "concurrent",
srcs = glob(["*.java"]),
deps = [
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
],
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/ThrowableRecordingRunnableWrapper.java b/src/main/java/com/google/devtools/build/lib/concurrent/ThrowableRecordingRunnableWrapper.java
index 0eb74f0..05f3331 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/ThrowableRecordingRunnableWrapper.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/ThrowableRecordingRunnableWrapper.java
@@ -14,9 +14,8 @@
package com.google.devtools.build.lib.concurrent;
import com.google.common.base.Preconditions;
+import com.google.common.flogger.GoogleLogger;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@@ -28,8 +27,7 @@
private final String name;
private AtomicReference<Throwable> errorRef = new AtomicReference<>();
- private static final Logger logger =
- Logger.getLogger(ThrowableRecordingRunnableWrapper.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
public ThrowableRecordingRunnableWrapper(String name) {
this.name = Preconditions.checkNotNull(name);
@@ -46,7 +44,7 @@
runnable.run();
} catch (Throwable error) {
errorRef.compareAndSet(null, error);
- logger.log(Level.SEVERE, "Error thrown by runnable in " + name, error);
+ logger.atSevere().withCause(error).log("Error thrown by runnable in %s", name);
}
};
}
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/BUILD b/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
index 4725234..294c2cb 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/BUILD
@@ -34,6 +34,7 @@
"//src/main/java/com/google/devtools/build/lib/util/io",
"//src/main/java/com/google/devtools/build/lib/vfs",
"//third_party:error_prone_annotations",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
],
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
index 67e58c5..23d56d1 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/LocalSpawnRunner.java
@@ -22,6 +22,7 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.actions.ActionExecutionMetadata;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.Artifact;
@@ -62,7 +63,6 @@
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@@ -75,7 +75,7 @@
private static final String UNHANDLED_EXCEPTION_MSG = "Unhandled exception running a local spawn";
private static final int LOCAL_EXEC_ERROR = -1;
- private static final Logger logger = Logger.getLogger(LocalSpawnRunner.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private final Path execRoot;
private final ResourceManager resourceManager;
@@ -245,7 +245,7 @@
Level level, @Nullable Throwable cause, @FormatString String fmt, Object... args) {
String msg = String.format(fmt, args);
String toLog = String.format("%s (#%d %s)", msg, id, desc());
- logger.log(level, toLog, cause);
+ logger.at(level).withCause(cause).log(toLog);
}
private String desc() {
@@ -265,10 +265,9 @@
long stateTime = (stateTimeBoxed == null) ? 0 : stateTimeBoxed;
stateTimes.put(currentState, stateTime + stepDelta);
- logger.info(
- String.format(
- "Step #%d time: %.3f delta: %.3f state: %s --> %s",
- id, totalDelta / 1000f, stepDelta / 1000f, currentState, newState));
+ logger.atInfo().log(
+ "Step #%d time: %.3f delta: %.3f state: %s --> %s",
+ id, totalDelta / 1000f, stepDelta / 1000f, currentState, newState);
currentState = newState;
}
@@ -283,7 +282,7 @@
/** Parse the request and run it locally. */
private SpawnResult start() throws InterruptedException, IOException {
- logger.info(String.format("starting local subprocess #%d, argv: %s", id, debugCmdString()));
+ logger.atInfo().log("starting local subprocess #%d, argv: %s", id, debugCmdString());
FileOutErr outErr = context.getFileOutErr();
String actionType = spawn.getResourceOwner().getMnemonic();
diff --git a/src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java b/src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java
index 9e545bb..7f59399 100644
--- a/src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/exec/local/XcodeLocalEnvProvider.java
@@ -16,6 +16,7 @@
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
import com.google.devtools.build.lib.rules.apple.DottedVersion;
@@ -31,7 +32,6 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import java.util.logging.Logger;
/**
* Adds to the given environment all variables that are dependent on system state of the host
@@ -46,7 +46,7 @@
*/
public final class XcodeLocalEnvProvider implements LocalEnvProvider {
- private static final Logger log = Logger.getLogger(XcodeLocalEnvProvider.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private final Map<String, String> clientEnv;
@@ -197,7 +197,7 @@
(key) -> {
try {
String sdkRoot = querySdkRoot(developerDir, sdkVersion, appleSdkPlatform);
- log.info("Queried Xcode SDK root with key " + key + " and got " + sdkRoot);
+ logger.atInfo().log("Queried Xcode SDK root with key %s and got %s", key, sdkRoot);
return sdkRoot;
} catch (IOException e) {
throw new UncheckedIOException(e);
@@ -290,7 +290,8 @@
(key) -> {
try {
String developerDir = queryDeveloperDir(binTools, version);
- log.info("Queried Xcode developer dir with key " + key + " and got " + developerDir);
+ logger.atInfo().log(
+ "Queried Xcode developer dir with key %s and got %s", key, developerDir);
return developerDir;
} catch (IOException e) {
throw new UncheckedIOException(e);
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/BUILD b/src/main/java/com/google/devtools/build/lib/includescanning/BUILD
index 1ef6b6e..fa9dfdc 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/BUILD
@@ -35,6 +35,7 @@
"//src/main/java/com/google/devtools/build/skyframe",
"//src/main/java/com/google/devtools/build/skyframe:skyframe-objects",
"//src/main/java/com/google/devtools/common/options",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
],
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
index 11d999d..9c75b1c 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeParser.java
@@ -23,6 +23,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.io.CharStreams;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@@ -66,8 +67,6 @@
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
@@ -82,7 +81,7 @@
class IncludeParser {
/**
- * File types supported by the grep-includes binary. {@link #fileType} must be kept is sync with
+ * File types supported by the grep-includes binary. {@link #fileType} must be kept in sync with
* //tools/cpp:grep-includes.
*/
public enum GrepIncludesFileType {
@@ -100,8 +99,7 @@
}
}
- private static final Logger logger = Logger.getLogger(IncludeParser.class.getName());
- private static final boolean LOG_FINE = logger.isLoggable(Level.FINE);
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* Immutable object representation of the four columns making up a single Rule
@@ -304,16 +302,12 @@
hints = Sets.newTreeSet(Artifact.EXEC_PATH_COMPARATOR);
}
PathFragment relativePath = PathFragment.create(m.replaceFirst(rule.findRoot));
- if (LOG_FINE) {
- logger.fine(
- "hint for " + rule.type + " " + firstMatchPathString + " root: " + relativePath);
- }
+ logger.atFine().log(
+ "hint for %s %s root: %s", rule.type, firstMatchPathString, relativePath);
if (!relativePath.getPathString().startsWith(ALLOWED_PREFIX)) {
- logger.warning(
- "Path "
- + relativePath.getPathString()
- + " to search after substitution does not start with "
- + ALLOWED_PREFIX);
+ logger.atWarning().log(
+ "Path %s to search after substitution does not start with %s",
+ relativePath.getPathString(), ALLOWED_PREFIX);
continue;
}
rulePaths.add(
@@ -335,15 +329,14 @@
(ContainingPackageLookupValue)
containingPackageLookupValues.get(relativePathKey).get();
} catch (NoSuchPackageException e) {
- logger.warning(
- "Unexpected exception when looking up containing package for "
- + relativePath
- + " (prodaccess expired?): "
- + e.getMessage());
+ logger.atWarning().withCause(e).log(
+ "Unexpected exception when looking up containing package for %s"
+ + " (prodaccess expired?)",
+ relativePath);
continue;
}
if (!containingPackageLookupValue.hasContainingPackage()) {
- logger.warning(relativePath + " not contained in any package: skipping");
+ logger.atWarning().log("%s not contained in any package: skipping", relativePath);
continue;
}
PathFragment packageFragment =
@@ -375,7 +368,7 @@
try {
globValue = (GlobValue) globEntry.getValue().get();
} catch (IOException e) {
- logger.warning("Error getting hints for " + packageFragment + ": " + e);
+ logger.atWarning().withCause(e).log("Error getting hints for %s", packageFragment);
continue;
}
for (PathFragment file : globValue.getMatches().toList()) {
@@ -409,18 +402,14 @@
if (hints == null) { hints = Sets.newTreeSet(); }
String relativePath = m.replaceFirst(rule.findRoot);
if (!relativePath.startsWith(ALLOWED_PREFIX)) {
- logger.warning(
- "Path "
- + relativePath
- + " to search after substitution does not start with "
- + ALLOWED_PREFIX);
+ logger.atWarning().log(
+ "Path %s to search after substitution does not start with %s",
+ relativePath, ALLOWED_PREFIX);
continue;
}
Path root = sourceRoot.getRoot().getRelative(relativePath);
- if (LOG_FINE) {
- logger.fine("hint for " + rule.type + " " + pathString + " root: " + root);
- }
+ logger.atFine().log("hint for %s %s root: %s", rule.type, pathString, root);
try {
// The assumption is made here that all files specified by this hint are under the same
// package path as the original file -- this filesystem tree traversal is completely
@@ -429,15 +418,13 @@
// different package paths. In that case, this traversal would fail to pick up
// foo/bar/**/*.h. No examples of this currently exist in the INCLUDE_HINTS
// file.
- if (LOG_FINE) {
- logger.fine("Globbing: " + root + " " + rule.findFilter);
- }
+ logger.atFine().log("Globbing: %s %s", root, rule.findFilter);
hints.addAll(new UnixGlob.Builder(root)
.setFilesystemCalls(syscallCache)
.addPattern(rule.findFilter)
.glob());
} catch (UnixGlob.BadPattern | IOException e) {
- logger.warning("Error in hint expansion: " + e);
+ logger.atWarning().withCause(e).log("Error in hint expansion");
}
}
if (hints != null && !hints.isEmpty()) {
@@ -476,9 +463,7 @@
Inclusion inclusion = new Inclusion(rule.findRoot, rule.type == Rule.Type.INCLUDE_QUOTE
? Kind.QUOTE : Kind.ANGLE);
hints.add(inclusion);
- if (LOG_FINE) {
- logger.fine("hint for " + rule.type + " " + pathString + " root: " + inclusion);
- }
+ logger.atFine().log("hint for %s %s root: %s", rule.type, pathString, inclusion);
}
if (hints != null && !hints.isEmpty()) {
return ImmutableList.copyOf(hints);
@@ -895,10 +880,8 @@
FileSystemUtils.readContent(actionExecutionContext.getInputPath(file)));
} catch (IOException e) {
if (remoteIncludeScanner != null && grepIncludes != null) {
- logger.log(
- Level.WARNING,
- "Falling back on remote parsing of " + actionExecutionContext.getInputPath(file),
- e);
+ logger.atWarning().withCause(e).log(
+ "Falling back on remote parsing of %s", actionExecutionContext.getInputPath(file));
inclusions =
remoteIncludeScanner.extractInclusions(
file,
@@ -956,10 +939,8 @@
FileSystemUtils.readContent(actionExecutionContext.getInputPath(file))));
} catch (IOException e) {
if (remoteIncludeScanner != null) {
- logger.log(
- Level.WARNING,
- "Falling back on remote parsing of " + actionExecutionContext.getInputPath(file),
- e);
+ logger.atWarning().withCause(e).log(
+ "Falling back on remote parsing of %s", actionExecutionContext.getInputPath(file));
inclusions =
remoteIncludeScanner.extractInclusionsAsync(
executor,
diff --git a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
index 6adcfc8..96b391f 100644
--- a/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
+++ b/src/main/java/com/google/devtools/build/lib/includescanning/IncludeScanningModule.java
@@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.devtools.build.lib.actions.ActionExecutionContext;
@@ -62,14 +63,13 @@
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.logging.Logger;
/**
* Module that provides implementations of {@link CppIncludeExtractionContext},
* {@link CppIncludeScanningContext}, and {@link SwigIncludeScanningContext}.
*/
public class IncludeScanningModule extends BlazeModule {
- private static final Logger log = Logger.getLogger(IncludeScanningModule.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private static final PathFragment INCLUDE_HINTS_FILENAME =
PathFragment.create("tools/cpp/INCLUDE_HINTS");
@@ -298,15 +298,14 @@
IncludeScanningOptions options = buildRequest.getOptions(IncludeScanningOptions.class);
int threads = options.includeScanningParallelism;
if (threads > 0) {
- log.info(
- String.format("Include scanning configured to use a pool with %d threads", threads));
+ logger.atInfo().log("Include scanning configured to use a pool with %d threads", threads);
if (options.useAsyncIncludeScanner) {
includePool = NamedForkJoinPool.newNamedPool("Include scanner", threads);
} else {
includePool = ExecutorUtil.newSlackPool(threads, "Include scanner");
}
} else {
- log.info("Include scanning configured to use a direct executor");
+ logger.atInfo().log("Include scanning configured to use a direct executor");
includePool = MoreExecutors.newDirectExecutorService();
}
includeScannerSupplier =
diff --git a/src/main/java/com/google/devtools/build/lib/shell/BUILD b/src/main/java/com/google/devtools/build/lib/shell/BUILD
index 6cf3450..5707eb9 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/shell/BUILD
@@ -19,6 +19,7 @@
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/protobuf:execution_statistics_java_proto",
"//third_party:auto_value",
+ "//third_party:flogger",
"//third_party:guava",
],
)
@@ -35,6 +36,7 @@
),
jars = [
"//third_party:auto_value-jars",
+ "//third_party:flogger-jars",
"//third_party:bootstrap_guava_and_error_prone-jars",
],
)
diff --git a/src/main/java/com/google/devtools/build/lib/shell/Command.java b/src/main/java/com/google/devtools/build/lib/shell/Command.java
index 0c3636b..6138201 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/Command.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/Command.java
@@ -16,6 +16,8 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.flogger.GoogleLogger;
+import com.google.common.flogger.LazyArg;
import com.google.common.io.ByteStreams;
import com.google.devtools.build.lib.shell.Consumers.OutErrConsumers;
import java.io.File;
@@ -25,8 +27,6 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.annotation.Nullable;
/**
@@ -113,8 +113,7 @@
*/
public final class Command {
- private static final Logger logger =
- Logger.getLogger("com.google.devtools.build.lib.shell.Command");
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/** Pass this value to {@link #execute} to indicate that no input should be written to stdin. */
public static final InputStream NO_INPUT = new NullInputStream();
@@ -394,9 +393,7 @@
}
private static void processInput(InputStream stdinInput, Subprocess process) {
- if (logger.isLoggable(Level.FINER)) {
- logger.finer(stdinInput.toString());
- }
+ logger.atFiner().log(stdinInput.toString());
try (OutputStream out = process.getOutputStream()) {
ByteStreams.copy(stdinInput, out);
} catch (IOException ioe) {
@@ -412,9 +409,6 @@
}
private void logCommand() {
- if (!logger.isLoggable(Level.FINE)) {
- return;
- }
- logger.fine(toDebugString());
+ logger.atFine().log("%s", (LazyArg<String>) this::toDebugString);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD
index 0b4c273..294c303 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/BUILD
@@ -31,6 +31,7 @@
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization/autocodec:registered-singleton",
"//src/main/java/com/google/devtools/build/lib/unsafe:string",
"//src/main/java/com/google/devtools/build/lib/unsafe:unsafe-provider",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/CodecScanner.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/CodecScanner.java
index 61b4706..02b4fb2 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/CodecScanner.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/CodecScanner.java
@@ -15,6 +15,7 @@
package com.google.devtools.build.lib.skyframe.serialization;
import com.google.common.base.Preconditions;
+import com.google.common.flogger.GoogleLogger;
import com.google.common.reflect.ClassPath;
import com.google.common.reflect.ClassPath.ClassInfo;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.RegisteredSingletonDoNotUse;
@@ -27,8 +28,6 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.stream.Stream;
/**
@@ -42,7 +41,7 @@
*/
public class CodecScanner {
- private static final Logger log = Logger.getLogger(CodecScanner.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/**
* Initializes an {@link ObjectCodecRegistry} builder by scanning a given package prefix.
@@ -50,10 +49,9 @@
* @param packagePrefix processes only classes in packages having this prefix
* @see CodecRegisterer
*/
- @SuppressWarnings("unchecked")
static ObjectCodecRegistry.Builder initializeCodecRegistry(String packagePrefix)
throws IOException, ReflectiveOperationException {
- log.info("Building ObjectCodecRegistry");
+ logger.atInfo().log("Building ObjectCodecRegistry");
ArrayList<Class<? extends ObjectCodec<?>>> codecs = new ArrayList<>();
ArrayList<Class<? extends CodecRegisterer<?>>> registerers = new ArrayList<>();
ObjectCodecRegistry.Builder builder = ObjectCodecRegistry.newBuilder();
@@ -141,7 +139,7 @@
return registered;
}
- @SuppressWarnings({"rawtypes", "unchecked"})
+ @SuppressWarnings("rawtypes")
private static void applyDefaultRegistration(
ObjectCodecRegistry.Builder builder,
HashSet<Class<? extends ObjectCodec<?>>> alreadyRegistered,
@@ -156,9 +154,8 @@
constructor.setAccessible(true);
builder.add((ObjectCodec<?>) constructor.newInstance());
} catch (NoSuchMethodException e) {
- log.log(
- Level.FINE,
- "Skipping registration of " + codecType + " because it had no default constructor.");
+ logger.atFine().withCause(e).log(
+ "Skipping registration of %s because it had no default constructor.", codecType);
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodec.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodec.java
index 2248b71..5973bc3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodec.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/DynamicCodec.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.skyframe.serialization;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.unsafe.UnsafeProvider;
import com.google.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
@@ -26,7 +27,6 @@
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
-import java.util.logging.Logger;
import sun.reflect.ReflectionFactory;
/**
@@ -35,7 +35,7 @@
* <p>TODO(shahan): replace Unsafe with VarHandle once it's available.
*/
public class DynamicCodec implements ObjectCodec<Object> {
- private static final Logger logger = Logger.getLogger(DynamicCodec.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
private final Class<?> type;
private final Constructor<?> constructor;
@@ -72,6 +72,7 @@
* @param type class of the field to serialize
* @param offset unsafe offset into obj where the field will be found
*/
+ @SuppressWarnings("LogAndThrow") // Want the full stack trace of serialization attempts.
private void serializeField(
SerializationContext context,
CodedOutputStream codedOut,
@@ -135,10 +136,8 @@
try {
context.serialize(UnsafeProvider.getInstance().getObject(obj, offset), codedOut);
} catch (SerializationException e) {
- logger.severe(
- String.format(
- "Unserializable object and superclass: %s %s",
- obj, obj.getClass().getSuperclass()));
+ logger.atSevere().withCause(e).log(
+ "Unserializable object and superclass: %s %s", obj, obj.getClass().getSuperclass());
e.addTrail(this.type);
throw e;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/BUILD b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/BUILD
index e049c69..3a9de36 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/BUILD
@@ -27,6 +27,7 @@
"//src/main/java/com/google/devtools/build/lib/vfs",
"//src/main/java/com/google/devtools/build/lib/vfs:pathfragment",
"//src/main/java/com/google/devtools/build/lib/vfs/inmemoryfs",
+ "//third_party:flogger",
"//third_party:guava",
"//third_party:jsr305",
"//third_party:junit4",
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/ObjectCodecTester.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/ObjectCodecTester.java
index 519bc21..62f9392 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/ObjectCodecTester.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/ObjectCodecTester.java
@@ -21,6 +21,7 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.skyframe.serialization.DeserializationContext;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.SerializationContext;
@@ -28,12 +29,10 @@
import com.google.protobuf.CodedInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/** Utility for testing {@link ObjectCodec} instances. */
public class ObjectCodecTester<T> {
- private static final Logger logger = Logger.getLogger(ObjectCodecTester.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/** Interface for testing successful deserialization of an object. */
@FunctionalInterface
@@ -101,13 +100,9 @@
verificationFunction.verifyDeserialized(subject, deserialized);
}
}
- logger.log(
- Level.INFO,
- underTest.getEncodedClass().getSimpleName()
- + " total serialized bytes = "
- + totalBytes
- + ", "
- + timer);
+ logger.atInfo().log(
+ "%s total serialized bytes = %d, %s",
+ underTest.getEncodedClass().getSimpleName(), totalBytes, timer);
}
/** Runs serialized bytes stability tests. */
@@ -156,7 +151,7 @@
/** Add subjects to be tested for serialization/deserialization. */
@SafeVarargs
- public final Builder<T> addSubjects(@SuppressWarnings("unchecked") T... subjects) {
+ public final Builder<T> addSubjects(T... subjects) {
return addSubjects(ImmutableList.copyOf(subjects));
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/SerializationTester.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/SerializationTester.java
index be788ea..7d87a68 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/SerializationTester.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/SerializationTester.java
@@ -21,6 +21,7 @@
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.flogger.GoogleLogger;
import com.google.devtools.build.lib.skyframe.serialization.AutoRegistry;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
import com.google.devtools.build.lib.skyframe.serialization.ObjectCodecRegistry;
@@ -32,8 +33,6 @@
import java.util.ArrayList;
import java.util.Map;
import java.util.Random;
-import java.util.logging.Level;
-import java.util.logging.Logger;
/**
* Utility for testing serialization of given subjects.
@@ -45,7 +44,7 @@
public static final int DEFAULT_JUNK_INPUTS = 20;
public static final int JUNK_LENGTH_UPPER_BOUND = 20;
- private static final Logger logger = Logger.getLogger(SerializationTester.class.getName());
+ private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();
/** Interface for testing successful deserialization of an object. */
@FunctionalInterface
@@ -178,13 +177,9 @@
verificationFunction.verifyDeserialized(subject, deserialized);
}
}
- logger.log(
- Level.INFO,
- subjects.get(0).getClass().getSimpleName()
- + " total serialized bytes = "
- + totalBytes
- + ", "
- + timer);
+ logger.atInfo().log(
+ "%s total serialized bytes = %d, %s",
+ subjects.get(0).getClass().getSimpleName(), totalBytes, timer);
}
/** Runs serialized bytes stability tests. */