diff --git a/java/google/registry/gcs/BUILD b/java/google/registry/gcs/BUILD index b1f52274f..cc41f5044 100644 --- a/java/google/registry/gcs/BUILD +++ b/java/google/registry/gcs/BUILD @@ -13,6 +13,8 @@ java_library( "@com_google_appengine_tools_appengine_gcs_client", "@com_google_code_findbugs_jsr305", "@com_google_dagger", + "@com_google_flogger", + "@com_google_flogger_system_backend", "@com_google_guava", ], ) diff --git a/java/google/registry/rde/BUILD b/java/google/registry/rde/BUILD index 930bf3440..e053676f4 100644 --- a/java/google/registry/rde/BUILD +++ b/java/google/registry/rde/BUILD @@ -32,6 +32,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_re2j", "@javax_servlet_api", diff --git a/java/google/registry/rde/RdeStagingAction.java b/java/google/registry/rde/RdeStagingAction.java index 050cc3e41..046ab5a2a 100644 --- a/java/google/registry/rde/RdeStagingAction.java +++ b/java/google/registry/rde/RdeStagingAction.java @@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Multimaps; -import com.google.common.logging.FormattingLogger; +import com.google.common.flogger.FluentLogger; import google.registry.config.RegistryConfig.Config; import google.registry.mapreduce.MapreduceRunner; import google.registry.mapreduce.inputs.EppResourceInputs; @@ -194,7 +194,7 @@ public final class RdeStagingAction implements Runnable { public static final String PATH = "/_dr/task/rdeStaging"; - private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); @Inject Clock clock; @Inject PendingDepositChecker pendingDepositChecker; @@ -218,12 +218,14 @@ public final class RdeStagingAction implements Runnable { manual ? getManualPendingDeposits() : getStandardPendingDeposits(); if (pendings.isEmpty()) { String message = "Nothing needs to be deposited"; - logger.info(message); + logger.atInfo().log(message); response.setStatus(SC_NO_CONTENT); response.setPayload(message); return; } - pendings.values().stream().map(Object::toString).forEach(logger::info); + for (PendingDeposit pending : pendings.values()) { + logger.atInfo().log("Pending deposit: %s", pending); + } RdeStagingMapper mapper = new RdeStagingMapper(lenient ? LENIENT : STRICT, pendings); response.sendJavaScriptRedirect(createJobPath(mrRunner @@ -261,7 +263,8 @@ public final class RdeStagingAction implements Runnable { pendingDepositChecker.getTldsAndWatermarksPendingDepositForRdeAndBrda(), pending -> { if (clock.nowUtc().isBefore(pending.watermark().plus(transactionCooldown))) { - logger.infofmt("Ignoring within %s cooldown: %s", transactionCooldown, pending); + logger.atInfo().log( + "Ignoring within %s cooldown: %s", transactionCooldown, pending); return false; } else { return true; diff --git a/java/google/registry/tools/server/BUILD b/java/google/registry/tools/server/BUILD index 2cee5e626..9d676a51d 100644 --- a/java/google/registry/tools/server/BUILD +++ b/java/google/registry/tools/server/BUILD @@ -29,6 +29,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", diff --git a/java/google/registry/tools/server/CreateOrUpdatePremiumListAction.java b/java/google/registry/tools/server/CreateOrUpdatePremiumListAction.java index 16c58df56..1e0957126 100644 --- a/java/google/registry/tools/server/CreateOrUpdatePremiumListAction.java +++ b/java/google/registry/tools/server/CreateOrUpdatePremiumListAction.java @@ -14,11 +14,12 @@ package google.registry.tools.server; +import static com.google.common.flogger.LazyArgs.lazy; + import com.google.common.collect.ImmutableMap; -import com.google.common.logging.FormattingLogger; +import com.google.common.flogger.FluentLogger; import google.registry.request.JsonResponse; import google.registry.request.Parameter; -import java.util.logging.Level; import javax.inject.Inject; /** @@ -26,7 +27,7 @@ import javax.inject.Inject; */ public abstract class CreateOrUpdatePremiumListAction implements Runnable { - protected static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final int MAX_LOGGING_PREMIUM_LIST_LENGTH = 1000; @@ -42,23 +43,25 @@ public abstract class CreateOrUpdatePremiumListAction implements Runnable { try { savePremiumList(); } catch (IllegalArgumentException e) { - logger.info(e, "Usage error in attempting to save premium list from nomulus tool command"); + logger.atInfo().withCause(e).log( + "Usage error in attempting to save premium list from nomulus tool command"); response.setPayload(ImmutableMap.of("error", e.toString(), "status", "error")); } catch (Exception e) { - logger.severe(e, "Unexpected error saving premium list from nomulus tool command"); + logger.atSevere().withCause(e).log( + "Unexpected error saving premium list from nomulus tool command"); response.setPayload(ImmutableMap.of("error", e.toString(), "status", "error")); } } /** Logs the premium list data at INFO, truncated if too long. */ void logInputData() { - if (logger.isLoggable(Level.INFO)) { - logger.infofmt( - "Received the following input data: %s", - (inputData.length() < MAX_LOGGING_PREMIUM_LIST_LENGTH) - ? inputData - : (inputData.substring(0, MAX_LOGGING_PREMIUM_LIST_LENGTH) + "")); - } + logger.atInfo().log( + "Received the following input data: %s", + lazy( + () -> + (inputData.length() < MAX_LOGGING_PREMIUM_LIST_LENGTH) + ? inputData + : (inputData.substring(0, MAX_LOGGING_PREMIUM_LIST_LENGTH) + ""))); } /** Creates a new premium list or updates an existing one. */ diff --git a/java/google/registry/tools/server/CreatePremiumListAction.java b/java/google/registry/tools/server/CreatePremiumListAction.java index 392ebd812..bbbc46db3 100644 --- a/java/google/registry/tools/server/CreatePremiumListAction.java +++ b/java/google/registry/tools/server/CreatePremiumListAction.java @@ -22,6 +22,7 @@ import static google.registry.request.Action.Method.POST; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; +import com.google.common.flogger.FluentLogger; import google.registry.model.registry.label.PremiumList; import google.registry.request.Action; import google.registry.request.Parameter; @@ -40,6 +41,8 @@ import javax.inject.Inject; ) public class CreatePremiumListAction extends CreateOrUpdatePremiumListAction { + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + public static final String OVERRIDE_PARAM = "override"; public static final String PATH = "/_dr/admin/createPremiumList"; @@ -54,7 +57,7 @@ public class CreatePremiumListAction extends CreateOrUpdatePremiumListAction { assertTldExists(name); } - logger.infofmt("Saving premium list for TLD %s", name); + logger.atInfo().log("Saving premium list for TLD %s", name); logInputData(); List inputDataPreProcessed = Splitter.on('\n').omitEmptyStrings().splitToList(inputData); @@ -65,7 +68,7 @@ public class CreatePremiumListAction extends CreateOrUpdatePremiumListAction { String.format( "Saved premium list %s with %d entries", premiumList.getName(), inputDataPreProcessed.size()); - logger.info(message); + logger.atInfo().log(message); response.setPayload(ImmutableMap.of("status", "success", "message", message)); } } diff --git a/java/google/registry/tools/server/UpdatePremiumListAction.java b/java/google/registry/tools/server/UpdatePremiumListAction.java index 223cd327f..c207c44a8 100644 --- a/java/google/registry/tools/server/UpdatePremiumListAction.java +++ b/java/google/registry/tools/server/UpdatePremiumListAction.java @@ -20,6 +20,7 @@ import static google.registry.request.Action.Method.POST; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableMap; +import com.google.common.flogger.FluentLogger; import google.registry.model.registry.label.PremiumList; import google.registry.request.Action; import google.registry.request.auth.Auth; @@ -38,6 +39,8 @@ import javax.inject.Inject; ) public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction { + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + public static final String PATH = "/_dr/admin/updatePremiumList"; @Inject UpdatePremiumListAction() {} @@ -50,7 +53,7 @@ public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction { "Could not update premium list %s because it doesn't exist.", name); - logger.infofmt("Updating premium list for TLD %s", name); + logger.atInfo().log("Updating premium list for TLD %s", name); logInputData(); List inputDataPreProcessed = Splitter.on('\n').omitEmptyStrings().splitToList(inputData); @@ -61,7 +64,7 @@ public class UpdatePremiumListAction extends CreateOrUpdatePremiumListAction { String.format( "Updated premium list %s with %d entries.", newPremiumList.getName(), inputDataPreProcessed.size()); - logger.info(message); + logger.atInfo().log(message); response.setPayload(ImmutableMap.of("status", "success", "message", message)); } } diff --git a/javatests/google/registry/backup/BUILD b/javatests/google/registry/backup/BUILD index a9421b242..d962c8d02 100644 --- a/javatests/google/registry/backup/BUILD +++ b/javatests/google/registry/backup/BUILD @@ -21,6 +21,8 @@ java_library( "@com_google_appengine_api_1_0_sdk//:testonly", "@com_google_appengine_tools_appengine_gcs_client", "@com_google_code_findbugs_jsr305", + "@com_google_flogger", + "@com_google_flogger_system_backend", "@com_google_guava", "@com_google_guava_testlib", "@com_google_truth", diff --git a/javatests/google/registry/backup/GcsDiffFileListerTest.java b/javatests/google/registry/backup/GcsDiffFileListerTest.java index d562f35e5..86f843694 100644 --- a/javatests/google/registry/backup/GcsDiffFileListerTest.java +++ b/javatests/google/registry/backup/GcsDiffFileListerTest.java @@ -32,6 +32,7 @@ import com.google.appengine.tools.cloudstorage.GcsServiceFactory; import com.google.appengine.tools.cloudstorage.ListItem; import com.google.appengine.tools.cloudstorage.ListResult; import com.google.common.collect.Iterators; +import com.google.common.flogger.LoggerConfig; import com.google.common.testing.TestLogHandler; import google.registry.testing.AppEngineRule; import java.io.IOException; @@ -42,7 +43,6 @@ import java.util.Iterator; import java.util.List; import java.util.concurrent.Callable; import java.util.logging.LogRecord; -import java.util.logging.Logger; import org.joda.time.DateTime; import org.junit.Before; import org.junit.Rule; @@ -79,7 +79,7 @@ public class GcsDiffFileListerTest { .build(), ByteBuffer.wrap(new byte[]{1, 2, 3})); } - Logger.getLogger(GcsDiffFileLister.class.getCanonicalName()).addHandler(logHandler); + LoggerConfig.getConfig(GcsDiffFileLister.class).addHandler(logHandler); } private Iterable extractTimesFromDiffFiles(List diffFiles) { diff --git a/javatests/google/registry/export/BUILD b/javatests/google/registry/export/BUILD index 7dfd368ab..6d85837d3 100644 --- a/javatests/google/registry/export/BUILD +++ b/javatests/google/registry/export/BUILD @@ -35,6 +35,8 @@ java_library( "@com_google_appengine_tools_appengine_gcs_client", "@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_re2j", diff --git a/javatests/google/registry/export/BigqueryPollJobActionTest.java b/javatests/google/registry/export/BigqueryPollJobActionTest.java index 4fd643d3a..8ccebbacc 100644 --- a/javatests/google/registry/export/BigqueryPollJobActionTest.java +++ b/javatests/google/registry/export/BigqueryPollJobActionTest.java @@ -34,6 +34,7 @@ import com.google.api.services.bigquery.model.JobStatus; import com.google.appengine.api.taskqueue.TaskOptions; import com.google.appengine.api.taskqueue.TaskOptions.Method; import com.google.appengine.api.taskqueue.dev.QueueStateInfo.TaskStateInfo; +import com.google.common.flogger.LoggerConfig; import google.registry.export.BigqueryPollJobAction.BigqueryPollJobEnqueuer; import google.registry.request.HttpException.BadRequestException; import google.registry.request.HttpException.NotModifiedException; @@ -52,7 +53,6 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.logging.Level; import java.util.logging.LogRecord; -import java.util.logging.Logger; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -90,7 +90,7 @@ public class BigqueryPollJobActionTest { action.projectId = PROJECT_ID; action.jobId = JOB_ID; action.chainedQueueName = () -> CHAINED_QUEUE_NAME; - Logger.getLogger(BigqueryPollJobAction.class.getName()).addHandler(logHandler); + LoggerConfig.getConfig(BigqueryPollJobAction.class).addHandler(logHandler); } private static TaskMatcher newPollJobTaskMatcher(String method) throws Exception { diff --git a/javatests/google/registry/flows/BUILD b/javatests/google/registry/flows/BUILD index 7f9fca041..515e1a7ee 100644 --- a/javatests/google/registry/flows/BUILD +++ b/javatests/google/registry/flows/BUILD @@ -43,6 +43,8 @@ java_library( "@com_google_appengine_testing", "@com_google_code_findbugs_jsr305", "@com_google_dagger", + "@com_google_flogger", + "@com_google_flogger_system_backend", "@com_google_guava", "@com_google_guava_testlib", "@com_google_monitoring_client_metrics", diff --git a/javatests/google/registry/flows/ExtensionManagerTest.java b/javatests/google/registry/flows/ExtensionManagerTest.java index 6fc646455..58f9d0eb9 100644 --- a/javatests/google/registry/flows/ExtensionManagerTest.java +++ b/javatests/google/registry/flows/ExtensionManagerTest.java @@ -20,6 +20,7 @@ import static google.registry.testing.JUnitBackports.assertThrows; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.flogger.LoggerConfig; import com.google.common.testing.TestLogHandler; import google.registry.flows.EppException.UnimplementedExtensionException; import google.registry.flows.ExtensionManager.UndeclaredServiceExtensionException; @@ -37,7 +38,6 @@ import google.registry.model.eppinput.EppInput.CommandExtension; import google.registry.testing.AppEngineRule; import google.registry.util.TypeUtils; import java.util.logging.LogRecord; -import java.util.logging.Logger; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -70,7 +70,7 @@ public class ExtensionManagerTest { @Test public void testUndeclaredExtensionsLogged() throws Exception { TestLogHandler handler = new TestLogHandler(); - Logger.getLogger(ExtensionManager.class.getCanonicalName()).addHandler(handler); + LoggerConfig.getConfig(ExtensionManager.class).addHandler(handler); ExtensionManager manager = new TestInstanceBuilder() .setEppRequestSource(EppRequestSource.TOOL) diff --git a/javatests/google/registry/flows/FlowReporterTest.java b/javatests/google/registry/flows/FlowReporterTest.java index de66441f7..f503fdb4e 100644 --- a/javatests/google/registry/flows/FlowReporterTest.java +++ b/javatests/google/registry/flows/FlowReporterTest.java @@ -23,6 +23,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.collect.ImmutableList; +import com.google.common.flogger.LoggerConfig; import com.google.common.testing.TestLogHandler; import google.registry.flows.annotations.ReportingSpec; import google.registry.model.eppcommon.Trid; @@ -33,7 +34,6 @@ import google.registry.model.reporting.IcannReportingTypes.ActivityReportField; import google.registry.testing.ShardableTestCase; import java.util.Map; import java.util.Optional; -import java.util.logging.Logger; import org.json.simple.JSONValue; import org.junit.Before; import org.junit.Test; @@ -64,7 +64,7 @@ public class FlowReporterTest extends ShardableTestCase { @Before public void before() { - Logger.getLogger(FlowReporter.class.getCanonicalName()).addHandler(handler); + LoggerConfig.getConfig(FlowReporter.class).addHandler(handler); flowReporter.trid = Trid.create("client-123", "server-456"); flowReporter.clientId = "TheRegistrar"; flowReporter.inputXmlBytes = "".getBytes(UTF_8); diff --git a/javatests/google/registry/flows/FlowRunnerTest.java b/javatests/google/registry/flows/FlowRunnerTest.java index bef481d24..750b32f5f 100644 --- a/javatests/google/registry/flows/FlowRunnerTest.java +++ b/javatests/google/registry/flows/FlowRunnerTest.java @@ -27,6 +27,7 @@ import com.google.appengine.api.users.User; import com.google.common.base.Joiner; import com.google.common.base.Splitter; import com.google.common.collect.ImmutableSet; +import com.google.common.flogger.LoggerConfig; import com.google.common.testing.TestLogHandler; import google.registry.model.eppcommon.Trid; import google.registry.model.eppoutput.EppOutput.ResponseOrGreeting; @@ -38,7 +39,6 @@ import google.registry.testing.FakeHttpSession; import google.registry.testing.ShardableTestCase; import java.util.List; import java.util.Optional; -import java.util.logging.Logger; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -68,7 +68,7 @@ public class FlowRunnerTest extends ShardableTestCase { @Before public void before() { - Logger.getLogger(FlowRunner.class.getCanonicalName()).addHandler(handler); + LoggerConfig.getConfig(FlowRunner.class).addHandler(handler); flowRunner.clientId = "TheRegistrar"; flowRunner.credentials = new PasswordOnlyTransportCredentials(); flowRunner.eppRequestSource = EppRequestSource.UNIT_TEST; diff --git a/javatests/google/registry/flows/ResourceFlowTestCase.java b/javatests/google/registry/flows/ResourceFlowTestCase.java index b5ccee7ca..4108ca5f4 100644 --- a/javatests/google/registry/flows/ResourceFlowTestCase.java +++ b/javatests/google/registry/flows/ResourceFlowTestCase.java @@ -27,6 +27,7 @@ import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Streams; +import com.google.common.flogger.LoggerConfig; import com.google.common.testing.TestLogHandler; import com.googlecode.objectify.Key; import google.registry.flows.FlowUtils.NotLoggedInException; @@ -45,7 +46,6 @@ import google.registry.testing.TaskQueueHelper.TaskMatcher; import google.registry.util.TypeUtils.TypeInstantiator; import java.util.Optional; import java.util.logging.Level; -import java.util.logging.Logger; import org.joda.time.DateTime; import org.joda.time.Duration; import org.json.simple.JSONValue; @@ -68,7 +68,7 @@ public abstract class ResourceFlowTestCase