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

@ -34,7 +34,6 @@ java_library(
]),
visibility = [":allowed-tools"],
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/backup",
"//java/google/registry/beam",
"//java/google/registry/bigquery",
@ -79,6 +78,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_http_client",
"@com_google_http_client_jackson2",

View file

@ -16,7 +16,6 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.logging.FormattingLogger.getLoggerForCallerClass;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static org.joda.time.DateTimeZone.UTC;
@ -24,7 +23,7 @@ import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.StatusValue;
@ -39,7 +38,7 @@ import org.joda.time.DateTime;
@Parameters(separators = " =", commandDescription = "Registry lock a domain via EPP.")
public class LockDomainCommand extends LockOrUnlockDomainCommand {
private static final FormattingLogger logger = getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Override
protected void initMutatingEppToolCommand() throws Exception {
@ -51,7 +50,7 @@ public class LockDomainCommand extends LockOrUnlockDomainCommand {
ImmutableSet<StatusValue> statusesToAdd =
Sets.difference(REGISTRY_LOCK_STATUSES, domainResource.getStatusValues()).immutableCopy();
if (statusesToAdd.isEmpty()) {
logger.infofmt("Domain '%s' is already locked and needs no updates.", domain);
logger.atInfo().log("Domain '%s' is already locked and needs no updates.", domain);
continue;
}

View file

@ -17,7 +17,7 @@ package google.registry.tools;
import com.beust.jcommander.Parameters;
import com.google.api.client.auth.oauth2.StoredCredential;
import com.google.api.client.util.store.AbstractDataStoreFactory;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import java.io.IOException;
import javax.inject.Inject;
@ -25,13 +25,13 @@ import javax.inject.Inject;
@Parameters(commandDescription = "Remove local OAuth credentials")
class LogoutCommand implements Command {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject AbstractDataStoreFactory dataStoreFactory;
@Override
public void run() throws IOException {
StoredCredential.getDefaultDataStore(dataStoreFactory).clear();
logger.info("Logged out - credentials have been removed.");
logger.atInfo().log("Logged out - credentials have been removed.");
}
}

View file

@ -16,7 +16,6 @@ package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.logging.FormattingLogger.getLoggerForCallerClass;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static org.joda.time.DateTimeZone.UTC;
@ -24,7 +23,7 @@ import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.StatusValue;
@ -39,7 +38,7 @@ import org.joda.time.DateTime;
@Parameters(separators = " =", commandDescription = "Registry unlock a domain via EPP.")
public class UnlockDomainCommand extends LockOrUnlockDomainCommand {
private static final FormattingLogger logger = getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Override
protected void initMutatingEppToolCommand() throws Exception {
@ -52,7 +51,7 @@ public class UnlockDomainCommand extends LockOrUnlockDomainCommand {
Sets.intersection(domainResource.getStatusValues(), REGISTRY_LOCK_STATUSES)
.immutableCopy();
if (statusesToRemove.isEmpty()) {
logger.infofmt("Domain '%s' is already unlocked and needs no updates.", domain);
logger.atInfo().log("Domain '%s' is already unlocked and needs no updates.", domain);
continue;
}

View file

@ -26,7 +26,7 @@ import com.beust.jcommander.Parameters;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.template.soy.data.SoyMapData;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainResource;
@ -42,7 +42,7 @@ import org.joda.time.DateTime;
@Parameters(separators = " =", commandDescription = "Update a new domain via EPP.")
final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Parameter(names = "--statuses", description = "Comma-separated list of statuses to set.")
private List<String> statuses = new ArrayList<>();
@ -223,7 +223,7 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
|| clearDsRecords;
if (!add && !remove && !change && !secdns) {
logger.infofmt("No changes need to be made to domain %s", domain);
logger.atInfo().log("No changes need to be made to domain %s", domain);
continue;
}

View file

@ -8,7 +8,6 @@ java_library(
name = "server",
srcs = glob(["*.java"]),
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/config",
"//java/google/registry/dns",
"//java/google/registry/export",

View file

@ -19,7 +19,7 @@ import static google.registry.request.Action.Method.POST;
import static java.util.Arrays.asList;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.groups.GroupsConnection;
import google.registry.groups.GroupsConnection.Role;
@ -50,7 +50,7 @@ public class CreateGroupsAction implements Runnable {
public static final String PATH = "/_dr/admin/createGroups";
public static final String CLIENT_ID_PARAM = "clientId";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final int NUM_SIMULTANEOUS_CONNECTIONS = 5;
@Inject GroupsConnection groupsConnection;
@ -97,11 +97,9 @@ public class CreateGroupsAction implements Runnable {
if (e.isPresent()) {
responseWriter.append(types.get(i).getDisplayName()).append(" => ");
e.get().printStackTrace(responseWriter);
logger.severefmt(
e.get(),
logger.atSevere().withCause(e.get()).log(
"Could not create Google Group for registrar %s for type %s",
registrar.getRegistrarName(),
types.get(i).toString());
registrar.getRegistrarName(), types.get(i));
} else {
responseWriter.printf("%s => Success%n", types.get(i).getDisplayName());
}
@ -110,7 +108,8 @@ public class CreateGroupsAction implements Runnable {
} else {
response.setStatus(SC_OK);
response.setPayload("Success!");
logger.infofmt("Successfully created groups for registrar: %s", registrar.getRegistrarName());
logger.atInfo().log(
"Successfully created groups for registrar: %s", registrar.getRegistrarName());
}
}
@ -128,7 +127,7 @@ public class CreateGroupsAction implements Runnable {
}
private void respondToBadRequest(String message) {
logger.severe(message);
logger.atSevere().log(message);
throw new BadRequestException(message);
}
}

View file

@ -24,7 +24,7 @@ import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.googlecode.objectify.VoidWork;
import com.googlecode.objectify.impl.EntityMetadata;
import google.registry.request.Action;
@ -54,7 +54,7 @@ import javax.inject.Inject;
)
public class DeleteEntityAction implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String PATH = "/_dr/admin/deleteEntity";
public static final String PARAM_RAW_KEYS = "rawKeys";
@ -99,7 +99,7 @@ public class DeleteEntityAction implements Runnable {
"Deleted %d raw entities and %d registered entities",
rawDeletions.size(),
ofyDeletions.size());
logger.info(message);
logger.atInfo().log(message);
response.setPayload(message);
}
@ -112,8 +112,8 @@ public class DeleteEntityAction implements Runnable {
try {
return Optional.ofNullable(getDatastoreService().get(rawKey));
} catch (EntityNotFoundException e) {
logger.warningfmt(
e, "Could not load entity from Datastore service with key %s", rawKey.toString());
logger.atWarning().withCause(e).log(
"Could not load entity from Datastore service with key %s", rawKey);
return Optional.empty();
}
}

View file

@ -30,7 +30,7 @@ import com.google.common.collect.ImmutableTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import com.google.common.collect.Streams;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.model.ImmutableObject;
import google.registry.request.JsonResponse;
import google.registry.request.Parameter;
@ -54,7 +54,7 @@ import javax.inject.Inject;
*/
public abstract class ListObjectsAction<T extends ImmutableObject> implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
public static final String FIELDS_PARAM = "fields";
public static final String PRINT_HEADER_ROW_PARAM = "printHeaderRow";
@ -107,7 +107,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
// Get the object data first, so we can figure out the list of all available fields using the
// data if necessary.
ImmutableSet<T> objects = loadObjects();
logger.infofmt("Loaded %d objects.", objects.size());
logger.atInfo().log("Loaded %d objects.", objects.size());
// Get the list of fields we should return.
ImmutableSet<String> fieldsToUse = getFieldsToUse(objects);
// Convert the data into a table.
@ -122,7 +122,7 @@ public abstract class ListObjectsAction<T extends ImmutableObject> implements Ru
"lines", lines,
"status", "success"));
} catch (IllegalArgumentException e) {
logger.warning(e, "Error while listing objects.");
logger.atWarning().withCause(e).log("Error while listing objects.");
// Don't return a non-200 response, since that will cause RegistryTool to barf instead of
// letting ListObjectsCommand parse the JSON response and return a clean error.
response.setPayload(

View file

@ -14,7 +14,6 @@
package google.registry.tools.server;
import static com.google.common.logging.FormattingLogger.getLoggerForCallerClass;
import static google.registry.mapreduce.inputs.EppResourceInputs.createEntityInput;
import static google.registry.model.EppResourceUtils.isActive;
import static google.registry.model.registry.Registries.assertTldsExist;
@ -24,7 +23,7 @@ import com.google.appengine.tools.mapreduce.Mapper;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.dns.DnsQueue;
import google.registry.mapreduce.MapreduceRunner;
import google.registry.model.domain.DomainResource;
@ -54,7 +53,7 @@ import org.joda.time.DateTimeZone;
)
public class RefreshDnsForAllDomainsAction implements Runnable {
private static final FormattingLogger logger = getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Inject MapreduceRunner mrRunner;
@Inject Response response;
@ -100,7 +99,8 @@ public class RefreshDnsForAllDomainsAction implements Runnable {
dnsQueue.addDomainRefreshTask(domainName);
getContext().incrementCounter("active domains refreshed");
} catch (Throwable t) {
logger.severefmt(t, "Error while refreshing DNS for domain %s", domainName);
logger.atSevere().withCause(t).log(
"Error while refreshing DNS for domain %s", domainName);
getContext().incrementCounter("active domains errored");
}
} else {