Migrate to Flogger (green)

This is a 'green' Flogger migration CL. Green CLs are intended to be as
safe as possible and should be easy to review and submit.

No changes should be necessary to the code itself prior to submission,
but small changes to BUILD files may be required.

Changes within files are completely independent of each other, so this CL
can be safely split up for review using tools such as Rosie.

For more information, see []
Base CL: 197826149

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198560170
This commit is contained in:
jianglai 2018-05-30 07:58:51 -07:00
parent 0d2fb3a8f0
commit 70b13596e4
178 changed files with 984 additions and 988 deletions

View file

@ -8,7 +8,6 @@ java_library(
name = "util",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//third_party/jaxb",
"//third_party/objectify:objectify-v4_1",
"@com_google_appengine_api_1_0_sdk",

View file

@ -17,7 +17,7 @@ package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.common.net.InetAddresses;
import java.io.Serializable;
import java.net.InetAddress;
@ -41,7 +41,7 @@ import javax.annotation.Nullable;
// TODO(b/21870796): Migrate to Guava version when this is open-sourced.
public class CidrAddressBlock implements Iterable<InetAddress>, Serializable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final InetAddress ip;
@ -343,7 +343,7 @@ public class CidrAddressBlock implements Iterable<InetAddress>, Serializable {
// not have been created with an invalid netmask and a valid
// netmask should have been successfully applied to "ipAddr" as long
// as it represents an address of the same family as "this.ip".
logger.warning(e, "Error while applying netmask.");
logger.atWarning().withCause(e).log("Error while applying netmask.");
return false;
}
}

View file

@ -17,7 +17,7 @@ package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -43,7 +43,7 @@ import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe
public class ImprovedInputStream extends FilterInputStream {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private long count;
private long mark = -1;
@ -126,7 +126,7 @@ public class ImprovedInputStream extends FilterInputStream {
if (in == null) {
return;
}
logger.infofmt("%s closed with %,d bytes read", getClass().getSimpleName(), count);
logger.atInfo().log("%s closed with %,d bytes read", getClass().getSimpleName(), count);
if (expected != -1 && count != expected) {
throw new IOException(String.format("%s expected %,d bytes but read %,d bytes",
getClass().getCanonicalName(), expected, count));

View file

@ -17,7 +17,7 @@ package google.registry.util;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@ -43,7 +43,7 @@ import javax.annotation.concurrent.NotThreadSafe;
@NotThreadSafe
public class ImprovedOutputStream extends FilterOutputStream {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private long count;
private final long expected;
@ -103,9 +103,9 @@ public class ImprovedOutputStream extends FilterOutputStream {
try {
flush();
} catch (IOException e) {
logger.warningfmt(e, "%s.flush() failed", getClass().getSimpleName());
logger.atWarning().withCause(e).log("%s.flush() failed", getClass().getSimpleName());
}
logger.infofmt("%s closed with %,d bytes written", getClass().getSimpleName(), count);
logger.atInfo().log("%s closed with %,d bytes written", getClass().getSimpleName(), count);
if (expected != -1 && count != expected) {
throw new IOException(String.format(
"%s expected %,d bytes but got %,d bytes", getClass().getSimpleName(), expected, count));

View file

@ -20,7 +20,7 @@ import static com.google.common.math.IntMath.pow;
import static google.registry.util.PredicateUtils.supertypeOf;
import com.google.common.collect.ImmutableSet;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.Serializable;
import java.util.Set;
import java.util.concurrent.Callable;
@ -34,7 +34,7 @@ public class Retrier implements Serializable {
private static final long serialVersionUID = 1167386907195735483L;
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Sleeper sleeper;
private final int attempts;
@ -171,5 +171,6 @@ public class Retrier implements Serializable {
private static final FailureReporter LOGGING_FAILURE_REPORTER =
(thrown, failures, maxAttempts) ->
logger.infofmt(thrown, "Retrying transient error, attempt %d/%d", failures, maxAttempts);
logger.atInfo().withCause(thrown).log(
"Retrying transient error, attempt %d/%d", failures, maxAttempts);
}

View file

@ -22,7 +22,7 @@ import com.google.appengine.api.taskqueue.TaskOptions;
import com.google.appengine.api.taskqueue.TransientFailureException;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
@ -32,7 +32,7 @@ public class TaskQueueUtils implements Serializable {
private static final long serialVersionUID = 7893211200220508362L;
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Retrier retrier;
@ -82,7 +82,7 @@ public class TaskQueueUtils implements Serializable {
return retrier.callWithRetry(
() -> {
for (TaskOptions task : tasks) {
logger.infofmt(
logger.atInfo().log(
"Enqueuing queue='%s' endpoint='%s'", queue.getQueueName(), task.getUrl());
}
return queue.add(tasks);