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

@ -12,7 +12,6 @@ java_library(
"//java/google/registry/ui/css:registrar_dbg.css.js",
],
deps = [
"//java/com/google/common/logging:formatting_logger",
"//java/google/registry/braintree",
"//java/google/registry/config",
"//java/google/registry/export/sheet",

View file

@ -28,7 +28,7 @@ import com.braintreegateway.TransactionRequest;
import com.braintreegateway.ValidationError;
import com.braintreegateway.ValidationErrors;
import com.google.common.collect.ImmutableMap;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import com.google.re2j.Pattern;
import google.registry.config.RegistryConfig.Config;
import google.registry.model.registrar.Registrar;
@ -99,7 +99,7 @@ import org.joda.money.Money;
)
public final class RegistrarPaymentAction implements Runnable, JsonAction {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private static final FormField<String, BigDecimal> AMOUNT_FIELD =
FormField.named("amount")
@ -158,7 +158,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
@Override
public Map<String, Object> handleJsonRequest(Map<String, ?> json) {
Registrar registrar = sessionUtils.getRegistrarForAuthResult(request, authResult);
logger.infofmt("Processing payment: %s", json);
logger.atInfo().log("Processing payment: %s", json);
String paymentMethodNonce;
Money amount;
String merchantAccountId;
@ -177,7 +177,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
throw new FormFieldException(CURRENCY_FIELD.name(), "Unsupported currency.");
}
} catch (FormFieldException e) {
logger.warning(e, "Form field error in RegistrarPaymentAction.");
logger.atWarning().withCause(e).log("Form field error in RegistrarPaymentAction.");
return JsonResponseHelper.createFormFieldError(e.getMessage(), e.getFieldName());
}
Result<Transaction> result =
@ -222,10 +222,11 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
Money amount =
Money.of(CurrencyUnit.of(transaction.getCurrencyIsoCode()),
transaction.getAmount().stripTrailingZeros());
logger.infofmt("Transaction for %s via %s %s with ID: %s",
logger.atInfo().log(
"Transaction for %s via %s %s with ID: %s",
amount,
transaction.getPaymentInstrumentType(), // e.g. credit_card, paypal_account
transaction.getStatus(), // e.g. SUBMITTED_FOR_SETTLEMENT
transaction.getPaymentInstrumentType(), // e.g. credit_card, paypal_account
transaction.getStatus(), // e.g. SUBMITTED_FOR_SETTLEMENT
transaction.getId());
return JsonResponseHelper
.create(SUCCESS, "Payment processed successfully", asList(
@ -245,7 +246,8 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
* Braintree - Transactions/Declines</a>
*/
private Map<String, Object> handleProcessorDeclined(Transaction transaction) {
logger.warningfmt("Processor declined: %s %s",
logger.atWarning().log(
"Processor declined: %s %s",
transaction.getProcessorResponseCode(), transaction.getProcessorResponseText());
return JsonResponseHelper.create(ERROR,
"Payment declined: " + transaction.getProcessorResponseText());
@ -263,7 +265,8 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
* Braintree - Transactions/Declines</a>
*/
private Map<String, Object> handleSettlementDecline(Transaction transaction) {
logger.warningfmt("Settlement declined: %s %s",
logger.atWarning().log(
"Settlement declined: %s %s",
transaction.getProcessorSettlementResponseCode(),
transaction.getProcessorSettlementResponseText());
return JsonResponseHelper.create(ERROR,
@ -286,7 +289,7 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
* Braintree - Fraud Tools/Overview</a>
*/
private Map<String, Object> handleRejection(Transaction transaction) {
logger.warningfmt("Gateway rejection: %s", transaction.getGatewayRejectionReason());
logger.atWarning().log("Gateway rejection: %s", transaction.getGatewayRejectionReason());
switch (transaction.getGatewayRejectionReason()) {
case DUPLICATE:
return JsonResponseHelper.create(ERROR, "Payment rejected: Possible duplicate.");
@ -307,7 +310,8 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
/** Handles a miscellaneous transaction processing error response. */
private Map<String, Object> handleMiscProcessorError(Transaction transaction) {
logger.warningfmt("Error processing transaction: %s %s %s",
logger.atWarning().log(
"Error processing transaction: %s %s %s",
transaction.getStatus(),
transaction.getProcessorResponseCode(),
transaction.getProcessorResponseText());
@ -330,7 +334,8 @@ public final class RegistrarPaymentAction implements Runnable, JsonAction {
List<ValidationError> errors = validationErrors.getAllDeepValidationErrors();
verify(!errors.isEmpty(), "Payment failed but validation error list was empty");
for (ValidationError error : errors) {
logger.warningfmt("Payment validation failed on field: %s\nCode: %s\nMessage: %s",
logger.atWarning().log(
"Payment validation failed on field: %s\nCode: %s\nMessage: %s",
error.getAttribute(), error.getCode(), error.getMessage());
}
return JsonResponseHelper

View file

@ -27,7 +27,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Multimap;
import com.google.common.collect.Streams;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.export.sheet.SyncRegistrarsSheetAction;
import google.registry.model.registrar.Registrar;
@ -69,7 +69,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
public static final String PATH = "/registrar-settings";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
static final String OP_PARAM = "op";
static final String ARGS_PARAM = "args";
@ -104,11 +104,9 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
@SuppressWarnings("unchecked")
Map<String, ?> args = (Map<String, Object>)
Optional.<Object>ofNullable(input.get(ARGS_PARAM)).orElse(ImmutableMap.of());
logger.infofmt(
logger.atInfo().log(
"Received request '%s' on registrar '%s' with args %s",
op,
initialRegistrar.getClientId(),
args);
op, initialRegistrar.getClientId(), args);
try {
switch (op) {
case "update":
@ -119,20 +117,14 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
return JsonResponseHelper.create(ERROR, "Unknown or unsupported operation: " + op);
}
} catch (FormFieldException e) {
logger.warningfmt(
e,
logger.atWarning().withCause(e).log(
"Failed to perform operation '%s' on registrar '%s' for args %s",
op,
initialRegistrar.getClientId(),
args);
op, initialRegistrar.getClientId(), args);
return JsonResponseHelper.createFormFieldError(e.getMessage(), e.getFieldName());
} catch (FormException e) {
logger.warningfmt(
e,
logger.atWarning().withCause(e).log(
"Failed to perform operation '%s' on registrar '%s' for args %s",
op,
initialRegistrar.getClientId(),
args);
op, initialRegistrar.getClientId(), args);
return JsonResponseHelper.create(ERROR, e.getMessage());
}
}
@ -154,7 +146,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
DateTime latestFromArgs =
RegistrarFormFields.LAST_UPDATE_TIME.extractUntyped(args).get();
if (!latestFromArgs.equals(latest)) {
logger.warningfmt(
logger.atWarning().log(
"registrar changed since reading the data! "
+ " Last updated at %s, but args data last updated at %s",
latest, latestFromArgs);
@ -171,8 +163,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA
changeRegistrarFields(registrar, builder, args);
// read the contacts from the request.
ImmutableSet<RegistrarContact> updatedContacts =
readContacts(registrar, args);
ImmutableSet<RegistrarContact> updatedContacts = readContacts(registrar, args);
if (!updatedContacts.isEmpty()) {
builder.setContactsRequireSyncing(true);
}

View file

@ -19,7 +19,7 @@ import static com.google.common.collect.Iterables.toArray;
import com.google.common.base.Joiner;
import com.google.common.collect.Streams;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.config.RegistryConfig.Config;
import google.registry.util.NonFinalForTesting;
import google.registry.util.SendEmailService;
@ -35,7 +35,7 @@ import javax.mail.internet.InternetAddress;
*/
public class SendEmailUtils {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final String gSuiteOutgoingEmailAddress;
private final String gSuiteOutoingEmailDisplayName;
@ -67,11 +67,8 @@ public class SendEmailUtils {
try {
return new InternetAddress(emailAddress, true);
} catch (AddressException e) {
logger.severefmt(
e,
"Could not send email to %s with subject '%s'.",
emailAddress,
subject);
logger.atSevere().withCause(e).log(
"Could not send email to %s with subject '%s'.", emailAddress, subject);
// Returning null excludes this address from the list of recipients on the
// email.
return null;
@ -87,11 +84,9 @@ public class SendEmailUtils {
msg.setText(body);
emailService.sendMessage(msg);
} catch (Throwable t) {
logger.severefmt(
t,
logger.atSevere().withCause(t).log(
"Could not email to addresses %s with subject '%s'.",
Joiner.on(", ").join(addresses),
subject);
Joiner.on(", ").join(addresses), subject);
return false;
}
return true;