Migrate to Flogger (yellow)

This is a 'yellow' Flogger migration CL. Yellow CLs should be mostly safe
but include changes that are notable for one reason or another. Manual
intervention may be required to address small issues.

The comments in this CL indicate cases where suggested code changes
should be double checked, or even modified. There may even be cases where
files outside this CL are affected by changes to things such as logger
visibility. However if a change does not have an associated comment then
it should be safe.

For more information, see []
Base CL: 197826149

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198097990
This commit is contained in:
jianglai 2018-05-25 13:56:19 -07:00
parent 92190f8699
commit 4be4fb0082
21 changed files with 69 additions and 52 deletions

View file

@ -13,6 +13,8 @@ java_library(
"//java/google/registry/util",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@org_bouncycastle_bcpg_jdk15on",
"@org_bouncycastle_bcpkix_jdk15on",

View file

@ -16,7 +16,7 @@ package google.registry.keyring.api;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.util.ComparingInvocationHandler;
import java.io.IOException;
import java.io.PrintWriter;
@ -43,8 +43,7 @@ import org.bouncycastle.openpgp.PGPPublicKey;
*/
public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring> {
@VisibleForTesting
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private ComparatorKeyring(Keyring original, Keyring second) {
super(Keyring.class, original, second);
@ -61,7 +60,7 @@ public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring>
@Override
protected void log(Method method, String message) {
logger.severefmt("ComparatorKeyring.%s: %s", method.getName(), message);
logger.atSevere().log("ComparatorKeyring.%s: %s", method.getName(), message);
}
/** Implements equals for the PGP classes. */
@ -124,7 +123,8 @@ public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring>
return Arrays.equals(a.getFingerprint(), b.getFingerprint())
&& Arrays.equals(a.getEncoded(), b.getEncoded());
} catch (IOException e) {
logger.severe(e, "ComparatorKeyring error: PGPPublicKey.getEncoded failed.");
logger.atSevere().withCause(e).log(
"ComparatorKeyring error: PGPPublicKey.getEncoded failed.");
return false;
}
}
@ -147,7 +147,8 @@ public final class ComparatorKeyring extends ComparingInvocationHandler<Keyring>
try {
return Arrays.equals(a.getEncoded(), b.getEncoded());
} catch (IOException e) {
logger.severe(e, "ComparatorKeyring error: PublicKeyPacket.getEncoded failed.");
logger.atSevere().withCause(e).log(
"ComparatorKeyring error: PublicKeyPacket.getEncoded failed.");
return false;
}
}

View file

@ -17,6 +17,8 @@ java_library(
"@com_google_appengine_tools_appengine_pipeline",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@javax_servlet_api",
"@joda_time",

View file

@ -23,7 +23,6 @@ import com.google.appengine.tools.mapreduce.InputReader;
import com.google.appengine.tools.mapreduce.ShardContext;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.logging.FormattingLogger;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.annotation.Entity;
import google.registry.model.EppResource;
@ -42,8 +41,6 @@ class ChildEntityReader<R extends EppResource, I extends ImmutableObject> extend
private static final long serialVersionUID = 7481761146349663848L;
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/** This reader uses an EppResourceEntityReader under the covers to iterate over EPP resources. */
private final EppResourceEntityReader<? extends R> eppResourceEntityReader;

View file

@ -19,7 +19,6 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.logging.FormattingLogger;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.cmd.Query;
import google.registry.model.ofy.CommitLogBucket;
@ -32,8 +31,6 @@ import org.joda.time.DateTime;
class CommitLogManifestReader
extends RetryingInputReader<Key<CommitLogManifest>, Key<CommitLogManifest>> {
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/**
* Memory estimation for this reader.
*

View file

@ -21,7 +21,6 @@ import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.api.datastore.QueryResultIterator;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.ImmutableSet;
import com.google.common.logging.FormattingLogger;
import com.googlecode.objectify.Key;
import com.googlecode.objectify.cmd.Query;
import google.registry.model.EppResource;
@ -32,8 +31,6 @@ import javax.annotation.Nullable;
/** Base class for {@link InputReader} classes that map over {@link EppResourceIndex}. */
abstract class EppResourceBaseReader<T> extends RetryingInputReader<EppResourceIndex, T> {
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/** Number of bytes in 1MB of memory, used for memory estimates. */
static final long ONE_MB = 1024 * 1024;

View file

@ -18,6 +18,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import com.google.appengine.tools.mapreduce.InputReader;
import com.google.common.collect.ImmutableSet;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.Key;
import google.registry.model.EppResource;
import google.registry.model.index.EppResourceIndex;
@ -27,6 +28,8 @@ import java.util.NoSuchElementException;
/** Reader that maps over {@link EppResourceIndex} and returns resources. */
class EppResourceEntityReader<R extends EppResource> extends EppResourceBaseReader<R> {
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final long serialVersionUID = -8042933349899971801L;
/**
@ -61,7 +64,7 @@ class EppResourceEntityReader<R extends EppResource> extends EppResourceBaseRead
Key<? extends EppResource> key = nextQueryResult().getKey();
EppResource resource = ofy().load().key(key).now();
if (resource == null) {
logger.severefmt("EppResourceIndex key %s points at a missing resource", key);
logger.atSevere().log("EppResourceIndex key %s points at a missing resource", key);
continue;
}
// Postfilter to distinguish polymorphic types (e.g. DomainBase and DomainResource).

View file

@ -31,6 +31,8 @@ java_library(
"@com_google_appengine_api_1_0_sdk",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_re2j",
"@io_bazel_rules_closure//closure/templates",

View file

@ -21,7 +21,7 @@ import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import com.google.appengine.api.users.User;
import com.google.common.base.Strings;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.Key;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.registrar.Registrar;
@ -40,7 +40,7 @@ import javax.servlet.http.HttpSession;
@Immutable
public class SessionUtils {
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String CLIENT_ID_ATTRIBUTE = "clientId";
@ -102,11 +102,12 @@ public class SessionUtils {
// Use the clientId if it exists
if (clientId != null) {
if (!hasAccessToRegistrar(clientId, user.getUserId())) {
logger.infofmt("Registrar Console access revoked: %s", clientId);
logger.atInfo().log("Registrar Console access revoked: %s", clientId);
session.invalidate();
return false;
}
logger.infofmt("Associating user %s with given registrar %s.", user.getUserId(), clientId);
logger.atInfo().log(
"Associating user %s with given registrar %s.", user.getUserId(), clientId);
return true;
}
@ -114,7 +115,7 @@ public class SessionUtils {
Optional<Registrar> registrar = findRegistrarForUser(user.getUserId());
if (registrar.isPresent()) {
verify(hasAccessToRegistrar(registrar.get(), user.getUserId()));
logger.infofmt(
logger.atInfo().log(
"Associating user %s with found registrar %s.",
user.getUserId(), registrar.get().getClientId());
session.setAttribute(CLIENT_ID_ATTRIBUTE, registrar.get().getClientId());
@ -125,20 +126,20 @@ public class SessionUtils {
// registryAdminClientId
if (userAuthInfo.isUserAdmin()) {
if (Strings.isNullOrEmpty(registryAdminClientId)) {
logger.infofmt(
logger.atInfo().log(
"Cannot associate admin user %s with configured client Id."
+ " ClientId is null or empty.",
user.getUserId());
return false;
}
if (!Registrar.loadByClientIdCached(registryAdminClientId).isPresent()) {
logger.infofmt(
logger.atInfo().log(
"Cannot associate admin user %s with configured client Id %s."
+ " Registrar does not exist.",
user.getUserId(), registryAdminClientId);
return false;
}
logger.infofmt(
logger.atInfo().log(
"User %s is an admin with no associated registrar."
+ " Automatically associating the user with configured client Id %s.",
user.getUserId(), registryAdminClientId);
@ -147,7 +148,7 @@ public class SessionUtils {
}
// We couldn't find any relevant clientId
logger.infofmt("User not associated with any Registrar: %s", user.getUserId());
logger.atInfo().log("User not associated with any Registrar: %s", user.getUserId());
return false;
}
@ -173,7 +174,7 @@ public class SessionUtils {
String registrarClientId = contact.getParent().getName();
Optional<Registrar> result = Registrar.loadByClientIdCached(registrarClientId);
if (!result.isPresent()) {
logger.severefmt(
logger.atSevere().log(
"A contact record exists for non-existent registrar: %s.", Key.create(contact));
}
return result;
@ -183,7 +184,7 @@ public class SessionUtils {
protected static boolean hasAccessToRegistrar(String clientId, final String gaeUserId) {
Optional<Registrar> registrar = Registrar.loadByClientIdCached(clientId);
if (!registrar.isPresent()) {
logger.warningfmt("Registrar '%s' disappeared from Datastore!", clientId);
logger.atWarning().log("Registrar '%s' disappeared from Datastore!", clientId);
return false;
}
return hasAccessToRegistrar(registrar.get(), gaeUserId);

View file

@ -15,6 +15,8 @@ java_library(
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_errorprone_error_prone_annotations",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_re2j",
"@com_ibm_icu_icu4j",

View file

@ -22,7 +22,7 @@ import com.google.apphosting.api.ApiProxy;
import com.google.apphosting.api.ApiProxy.Environment;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Iterables;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.util.Collections;
import javax.inject.Inject;
@ -31,8 +31,7 @@ public class RequestStatusCheckerImpl implements RequestStatusChecker {
private static final long serialVersionUID = -8161977032130865437L;
@VisibleForTesting
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@VisibleForTesting
static LogService logService = LogServiceFactory.getLogService();
@ -56,7 +55,7 @@ public class RequestStatusCheckerImpl implements RequestStatusChecker {
public String getLogId() {
String requestLogId =
ApiProxy.getCurrentEnvironment().getAttributes().get(REQUEST_LOG_ID_KEY).toString();
logger.infofmt("Current requestLogId: %s", requestLogId);
logger.atInfo().log("Current requestLogId: %s", requestLogId);
// We want to make sure there actually is a log to query for this request, even if the request
// dies right after this call.
//
@ -85,12 +84,12 @@ public class RequestStatusCheckerImpl implements RequestStatusChecker {
// request is too new (it can take several seconds until the logs are available for "fetch").
// So we have to assume it's "running" in that case.
if (requestLogs == null) {
logger.infofmt(
logger.atInfo().log(
"Queried an unrecognized requestLogId %s - assume it's running", requestLogId);
return true;
}
logger.infofmt(
"Found logs for requestLogId %s - isFinished: %s", requestLogId, requestLogs.isFinished());
logger.atInfo().log(
"Found logs for requestLogId %s - isFinished: %b", requestLogId, requestLogs.isFinished());
return !requestLogs.isFinished();
}
}

View file

@ -20,6 +20,8 @@ java_library(
"@com_google_auto_value",
"@com_google_code_findbugs_jsr305",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_monitoring_client_metrics",
"@javax_servlet_api",

View file

@ -21,8 +21,8 @@ import static google.registry.util.DomainNameUtils.canonicalizeDomainName;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
import com.google.common.base.Joiner;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.CharStreams;
import com.google.common.logging.FormattingLogger;
import com.google.common.net.InetAddresses;
import com.google.common.net.InternetDomainName;
import google.registry.config.RegistryConfig.Config;
@ -63,7 +63,7 @@ import org.joda.time.DateTime;
*/
class WhoisReader {
static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
/**
* These are strings that will always trigger a specific query type when they are sent at
@ -115,7 +115,7 @@ class WhoisReader {
// Try to parse the argument as a domain name.
try {
logger.infofmt("Attempting domain lookup command using domain name %s", tokens.get(1));
logger.atInfo().log("Attempting domain lookup command using domain name %s", tokens.get(1));
return commandFactory.domainLookup(
InternetDomainName.from(canonicalizeDomainName(tokens.get(1))), fullOutput);
} catch (IllegalArgumentException iae) {
@ -134,7 +134,7 @@ class WhoisReader {
// Try to parse the argument as an IP address.
try {
logger.infofmt(
logger.atInfo().log(
"Attempting nameserver lookup command using %s as an IP address", tokens.get(1));
return commandFactory.nameserverLookupByIp(InetAddresses.forString(tokens.get(1)));
} catch (IllegalArgumentException iae) {
@ -143,7 +143,7 @@ class WhoisReader {
// Try to parse the argument as a host name.
try {
logger.infofmt(
logger.atInfo().log(
"Attempting nameserver lookup command using %s as a hostname", tokens.get(1));
return commandFactory.nameserverLookupByHost(InternetDomainName.from(
canonicalizeDomainName(tokens.get(1))));
@ -163,7 +163,7 @@ class WhoisReader {
"Too few arguments to '%s' command.", REGISTRAR_LOOKUP_COMMAND));
}
String registrarLookupArgument = Joiner.on(' ').join(tokens.subList(1, tokens.size()));
logger.infofmt(
logger.atInfo().log(
"Attempting registrar lookup command using registrar %s", registrarLookupArgument);
return commandFactory.registrarLookup(registrarLookupArgument);
}
@ -172,7 +172,7 @@ class WhoisReader {
if (tokens.size() == 1) {
// Try to parse it as an IP address. If successful, then this is a lookup on a nameserver.
try {
logger.infofmt("Attempting nameserver lookup using %s as an IP address", arg1);
logger.atInfo().log("Attempting nameserver lookup using %s as an IP address", arg1);
return commandFactory.nameserverLookupByIp(InetAddresses.forString(arg1));
} catch (IllegalArgumentException iae) {
// Silently ignore this exception.
@ -187,19 +187,19 @@ class WhoisReader {
Optional<InternetDomainName> tld = findTldForName(targetName);
if (!tld.isPresent()) {
// This target is not under any configured TLD, so just try it as a registrar name.
logger.infofmt("Attempting registrar lookup using %s as a registrar", arg1);
logger.atInfo().log("Attempting registrar lookup using %s as a registrar", arg1);
return new RegistrarLookupCommand(arg1);
}
// If the target is exactly one level above the TLD, then this is a second level domain
// (SLD) and we should do a domain lookup on it.
if (targetName.parent().equals(tld.get())) {
logger.infofmt("Attempting domain lookup using %s as a domain name", targetName);
logger.atInfo().log("Attempting domain lookup using %s as a domain name", targetName);
return commandFactory.domainLookup(targetName, fullOutput);
}
// The target is more than one level above the TLD, so we'll assume it's a nameserver.
logger.infofmt("Attempting nameserver lookup using %s as a hostname", targetName);
logger.atInfo().log("Attempting nameserver lookup using %s as a hostname", targetName);
return commandFactory.nameserverLookupByHost(targetName);
} catch (IllegalArgumentException e) {
// Silently ignore this exception.
@ -211,7 +211,7 @@ class WhoisReader {
// The only case left is that there are multiple tokens with no particular command given. We'll
// assume this is a registrar lookup, since there's really nothing else it could be.
String registrarLookupArgument = Joiner.on(' ').join(tokens);
logger.infofmt(
logger.atInfo().log(
"Attempting registrar lookup employing %s as a registrar", registrarLookupArgument);
return commandFactory.registrarLookup(registrarLookupArgument);
}

View file

@ -13,6 +13,8 @@ java_library(
deps = [
"//java/google/registry/keyring/api",
"//javatests/google/registry/testing",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava_testlib",
"@com_google_truth",
"@com_google_truth_extensions_truth_java8_extension",

View file

@ -21,6 +21,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import com.google.common.flogger.LoggerConfig;
import com.google.common.testing.TestLogHandler;
import java.io.IOException;
import java.util.logging.Level;
@ -80,12 +81,12 @@ public class ComparatorKeyringTest {
@Before
public void setUp() {
ComparatorKeyring.logger.getFormattingLogger().addHandler(testLogHandler);
LoggerConfig.getConfig(ComparatorKeyring.class).addHandler(testLogHandler);
}
@After
public void tearDown() {
ComparatorKeyring.logger.getFormattingLogger().removeHandler(testLogHandler);
LoggerConfig.getConfig(ComparatorKeyring.class).removeHandler(testLogHandler);
}
@Test

View file

@ -27,6 +27,8 @@ java_library(
"//third_party/objectify:objectify-v4_1",
"@com_braintreepayments_gateway_braintree_java",
"@com_google_appengine_api_1_0_sdk//:testonly",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_guava_testlib",
"@com_google_truth",

View file

@ -28,6 +28,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import com.google.appengine.api.users.User;
import com.google.common.flogger.LoggerConfig;
import com.google.common.testing.NullPointerTester;
import com.google.common.testing.TestLogHandler;
import google.registry.model.registrar.RegistrarContact;
@ -77,7 +78,7 @@ public class SessionUtilsTest {
@Before
public void before() throws Exception {
SessionUtils.logger.getFormattingLogger().addHandler(testLogHandler);
LoggerConfig.getConfig(SessionUtils.class).addHandler(testLogHandler);
sessionUtils = new SessionUtils();
sessionUtils.registryAdminClientId = ADMIN_CLIENT_ID;
persistResource(loadRegistrar(ADMIN_CLIENT_ID));
@ -86,7 +87,7 @@ public class SessionUtilsTest {
@After
public void after() throws Exception {
SessionUtils.logger.getFormattingLogger().removeHandler(testLogHandler);
LoggerConfig.getConfig(SessionUtils.class).removeHandler(testLogHandler);
}
/** User needs to be logged in before calling checkRegistrarConsoleLogin */

View file

@ -16,6 +16,8 @@ java_library(
"//javatests/google/registry/testing",
"@com_google_appengine_api_1_0_sdk",
"@com_google_code_findbugs_jsr305",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_guava_testlib",
"@com_google_re2j",

View file

@ -25,6 +25,7 @@ import com.google.appengine.api.log.LogService;
import com.google.appengine.api.log.RequestLogs;
import com.google.apphosting.api.ApiProxy;
import com.google.common.collect.ImmutableList;
import com.google.common.flogger.LoggerConfig;
import com.google.common.testing.TestLogHandler;
import google.registry.testing.AppEngineRule;
import java.util.logging.Level;
@ -69,12 +70,12 @@ public final class RequestStatusCheckerImplTest {
public AppEngineRule appEngineRule = AppEngineRule.builder().build();
@Before public void setUp() {
RequestStatusCheckerImpl.logger.getFormattingLogger().addHandler(logHandler);
LoggerConfig.getConfig(RequestStatusCheckerImpl.class).addHandler(logHandler);
RequestStatusCheckerImpl.logService = mock(LogService.class);
}
@After public void tearDown() {
RequestStatusCheckerImpl.logger.getFormattingLogger().removeHandler(logHandler);
LoggerConfig.getConfig(RequestStatusCheckerImpl.class).removeHandler(logHandler);
}
// If a logId is unrecognized, it could be that the log hasn't been uploaded yet - so we assume

View file

@ -22,6 +22,8 @@ java_library(
"@com_google_appengine_api_1_0_sdk",
"@com_google_appengine_testing",
"@com_google_dagger",
"@com_google_flogger",
"@com_google_flogger_system_backend",
"@com_google_guava",
"@com_google_guava_testlib",
"@com_google_truth",

View file

@ -19,6 +19,7 @@ import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.JUnitBackports.assertThrows;
import static google.registry.testing.LogsSubject.assertAboutLogs;
import com.google.common.flogger.LoggerConfig;
import com.google.common.testing.TestLogHandler;
import google.registry.testing.AppEngineRule;
import google.registry.testing.FakeClock;
@ -41,7 +42,7 @@ public class WhoisReaderTest {
@Before
public void init() {
createTlds("tld", "xn--kgbechtv", "1.test");
WhoisReader.logger.getFormattingLogger().addHandler(testLogHandler);
LoggerConfig.getConfig(WhoisReader.class).addHandler(testLogHandler);
}
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})