Migrating to fluent logging (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: 197331037

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=197466715
This commit is contained in:
jianglai 2018-05-21 15:08:53 -07:00
parent 3983f32795
commit 05f166918f
12 changed files with 64 additions and 78 deletions

View file

@ -19,7 +19,6 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import dagger.Lazy; import dagger.Lazy;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
@ -73,8 +72,6 @@ public class CertificateModule {
@Qualifier @Qualifier
public @interface Prod {} public @interface Prod {}
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
static { static {
Security.addProvider(new BouncyCastleProvider()); Security.addProvider(new BouncyCastleProvider());
} }
@ -159,8 +156,7 @@ public class CertificateModule {
listBuilder.add(obj); listBuilder.add(obj);
} }
} catch (IOException e) { } catch (IOException e) {
logger.severe(e, "Cannot parse PEM file correctly."); throw new RuntimeException("Cannot parse PEM file correctly.", e);
throw new RuntimeException(e);
} }
} }
return listBuilder.build(); return listBuilder.build();
@ -176,8 +172,8 @@ public class CertificateModule {
try { try {
return converter.getKeyPair(pemKeyPair).getPrivate(); return converter.getKeyPair(pemKeyPair).getPrivate();
} catch (PEMException e) { } catch (PEMException e) {
logger.severefmt(e, "Error converting private key: %s", pemKeyPair); throw new RuntimeException(
throw new RuntimeException(e); String.format("Error converting private key: %s", pemKeyPair), e);
} }
}; };
ImmutableList<PrivateKey> privateKeys = ImmutableList<PrivateKey> privateKeys =
@ -200,8 +196,8 @@ public class CertificateModule {
try { try {
return converter.getCertificate(certificateHolder); return converter.getCertificate(certificateHolder);
} catch (CertificateException e) { } catch (CertificateException e) {
logger.severefmt(e, "Error converting certificate: %s", certificateHolder); throw new RuntimeException(
throw new RuntimeException(e); String.format("Error converting certificate: %s", certificateHolder), e);
} }
}; };
ImmutableList<X509Certificate> certificates = ImmutableList<X509Certificate> certificates =

View file

@ -17,7 +17,6 @@ package google.registry.proxy;
import static google.registry.util.ResourceUtils.readResourceBytes; import static google.registry.util.ResourceUtils.readResourceBytes;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.logging.FormattingLogger;
import dagger.Module; import dagger.Module;
import dagger.Provides; import dagger.Provides;
import dagger.multibindings.IntoSet; import dagger.multibindings.IntoSet;
@ -52,8 +51,6 @@ import javax.inject.Singleton;
@Module @Module
public class EppProtocolModule { public class EppProtocolModule {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
/** Dagger qualifier to provide epp protocol related handlers and other bindings. */ /** Dagger qualifier to provide epp protocol related handlers and other bindings. */
@Qualifier @Qualifier
public @interface EppProtocol {} public @interface EppProtocol {}
@ -136,8 +133,7 @@ public class EppProtocolModule {
try { try {
return readResourceBytes(EppProtocolModule.class, "resources/hello.xml").read(); return readResourceBytes(EppProtocolModule.class, "resources/hello.xml").read();
} catch (IOException e) { } catch (IOException e) {
logger.severe(e, "Cannot read EPP <hello> message file."); throw new RuntimeException("Cannot read EPP <hello> message file.", e);
throw new RuntimeException(e);
} }
} }

View file

@ -19,7 +19,7 @@ import com.google.api.client.googleapis.util.Utils;
import com.google.api.services.monitoring.v3.Monitoring; import com.google.api.services.monitoring.v3.Monitoring;
import com.google.api.services.monitoring.v3.model.MonitoredResource; import com.google.api.services.monitoring.v3.model.MonitoredResource;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.monitoring.metrics.MetricReporter; import com.google.monitoring.metrics.MetricReporter;
import com.google.monitoring.metrics.MetricWriter; import com.google.monitoring.metrics.MetricWriter;
@ -35,7 +35,7 @@ import javax.inject.Singleton;
@Module @Module
public class MetricsModule { public class MetricsModule {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
@Singleton @Singleton
@Provides @Provides
@ -89,7 +89,7 @@ public class MetricsModule {
} else { } else {
monitoredResource.setType("gke_container").setLabels(metricParameters.makeLabelsMap()); monitoredResource.setType("gke_container").setLabels(metricParameters.makeLabelsMap());
} }
logger.infofmt("Monitored resource: %s", monitoredResource); logger.atInfo().log("Monitored resource: %s", monitoredResource);
return monitoredResource; return monitoredResource;
} }

View file

@ -20,7 +20,6 @@ import static google.registry.proxy.handler.RelayHandler.RELAY_CHANNEL_KEY;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.common.logging.FormattingLogger;
import com.google.monitoring.metrics.MetricReporter; import com.google.monitoring.metrics.MetricReporter;
import google.registry.proxy.Protocol.BackendProtocol; import google.registry.proxy.Protocol.BackendProtocol;
import google.registry.proxy.Protocol.FrontendProtocol; import google.registry.proxy.Protocol.FrontendProtocol;
@ -51,9 +50,7 @@ import javax.inject.Provider;
*/ */
public class ProxyServer implements Runnable { public class ProxyServer implements Runnable {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
// TODO (b/78466557): remove dummy flogger.
private static final FluentLogger flogger = FluentLogger.forEnclosingClass();
/** Maximum length of the queue of incoming connections. */ /** Maximum length of the queue of incoming connections. */
private static final int MAX_SOCKET_BACKLOG = 128; private static final int MAX_SOCKET_BACKLOG = 128;
@ -127,18 +124,16 @@ public class ProxyServer implements Runnable {
// Outbound channel established successfully, inbound channel can start reading. // Outbound channel established successfully, inbound channel can start reading.
// This setter also calls channel.read() to request read operation. // This setter also calls channel.read() to request read operation.
inboundChannel.config().setAutoRead(true); inboundChannel.config().setAutoRead(true);
logger.infofmt( logger.atInfo().log(
"Relay established: %s <-> %s\nSERVER: %s\nCLIENT: %s", "Relay established: %s <-> %s\nSERVER: %s\nCLIENT: %s",
inboundProtocol.name(), inboundProtocol.name(),
outboundProtocol.name(), outboundProtocol.name(),
inboundChannel, inboundChannel,
outboundChannel); outboundChannel);
} else { } else {
logger.severefmt( logger.atSevere().withCause(future.cause()).log(
future.cause(),
"Cannot connect to relay channel for %s protocol connection from %s.", "Cannot connect to relay channel for %s protocol connection from %s.",
inboundProtocol.name(), inboundProtocol.name(), inboundChannel.remoteAddress().getHostName());
inboundChannel.remoteAddress().getHostName());
} }
}); });
} }
@ -173,15 +168,15 @@ public class ProxyServer implements Runnable {
// Wait for binding to be established for each listening port. // Wait for binding to be established for each listening port.
ChannelFuture serverChannelFuture = serverBootstrap.bind(port).sync(); ChannelFuture serverChannelFuture = serverBootstrap.bind(port).sync();
if (serverChannelFuture.isSuccess()) { if (serverChannelFuture.isSuccess()) {
flogger.atInfo().log( logger.atInfo().log(
"Start listening on port %s for %s protocol.", port, protocol.name()); "Start listening on port %s for %s protocol.", port, protocol.name());
Channel serverChannel = serverChannelFuture.channel(); Channel serverChannel = serverChannelFuture.channel();
serverChannel.attr(PROTOCOL_KEY).set(protocol); serverChannel.attr(PROTOCOL_KEY).set(protocol);
portToChannelMap.put(port, serverChannel); portToChannelMap.put(port, serverChannel);
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.severefmt( logger.atSevere().withCause(e).log(
e, "Cannot listen on port %s for %s protocol.", port, protocol.name()); "Cannot listen on port %d for %s protocol.", port, protocol.name());
} }
}); });
@ -191,19 +186,17 @@ public class ProxyServer implements Runnable {
try { try {
// Block until all server channels are closed. // Block until all server channels are closed.
ChannelFuture unusedFuture = channel.closeFuture().sync(); ChannelFuture unusedFuture = channel.closeFuture().sync();
logger.infofmt( logger.atInfo().log(
"Stop listening on port %s for %s protocol.", "Stop listening on port %d for %s protocol.",
port, channel.attr(PROTOCOL_KEY).get().name()); port, channel.attr(PROTOCOL_KEY).get().name());
} catch (InterruptedException e) { } catch (InterruptedException e) {
logger.severefmt( logger.atSevere().withCause(e).log(
e, "Listening on port %d for %s protocol interrupted.",
"Listening on port %s for %s protocol interrupted.", port, channel.attr(PROTOCOL_KEY).get().name());
port,
channel.attr(PROTOCOL_KEY).get().name());
} }
}); });
} finally { } finally {
logger.info("Shutting down server..."); logger.atInfo().log("Shutting down server...");
Future<?> unusedFuture = eventGroup.shutdownGracefully(); Future<?> unusedFuture = eventGroup.shutdownGracefully();
} }
} }
@ -223,9 +216,10 @@ public class ProxyServer implements Runnable {
MetricReporter metricReporter = proxyComponent.metricReporter(); MetricReporter metricReporter = proxyComponent.metricReporter();
try { try {
metricReporter.startAsync().awaitRunning(10, TimeUnit.SECONDS); metricReporter.startAsync().awaitRunning(10, TimeUnit.SECONDS);
logger.info("Started up MetricReporter"); logger.atInfo().log("Started up MetricReporter");
} catch (TimeoutException timeoutException) { } catch (TimeoutException timeoutException) {
logger.severefmt("Failed to initialize MetricReporter: %s", timeoutException); logger.atSevere().withCause(timeoutException).log(
"Failed to initialize MetricReporter: %s", timeoutException);
} }
Runtime.getRuntime() Runtime.getRuntime()
@ -234,9 +228,10 @@ public class ProxyServer implements Runnable {
() -> { () -> {
try { try {
metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS); metricReporter.stopAsync().awaitTerminated(10, TimeUnit.SECONDS);
logger.info("Shut down MetricReporter"); logger.atInfo().log("Shut down MetricReporter");
} catch (TimeoutException timeoutException) { } catch (TimeoutException timeoutException) {
logger.warningfmt("Failed to stop MetricReporter: %s", timeoutException); logger.atWarning().withCause(timeoutException).log(
"Failed to stop MetricReporter: %s", timeoutException);
} }
})); }));

View file

@ -20,7 +20,7 @@ import static google.registry.proxy.handler.ProxyProtocolHandler.REMOTE_ADDRESS_
import static google.registry.proxy.handler.SslServerInitializer.CLIENT_CERTIFICATE_PROMISE_KEY; import static google.registry.proxy.handler.SslServerInitializer.CLIENT_CERTIFICATE_PROMISE_KEY;
import static google.registry.util.X509Utils.getCertificateHash; import static google.registry.util.X509Utils.getCertificateHash;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import google.registry.proxy.metric.FrontendMetrics; import google.registry.proxy.metric.FrontendMetrics;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -40,7 +40,7 @@ import java.util.function.Supplier;
/** Handler that processes EPP protocol logic. */ /** Handler that processes EPP protocol logic. */
public class EppServiceHandler extends HttpsRelayServiceHandler { public class EppServiceHandler extends HttpsRelayServiceHandler {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
/** /**
* Attribute key to the client certificate hash whose value is set when the certificate promise is * Attribute key to the client certificate hash whose value is set when the certificate promise is
@ -118,7 +118,7 @@ public class EppServiceHandler extends HttpsRelayServiceHandler {
"epp", sslClientCertificateHash, ctx.channel()); "epp", sslClientCertificateHash, ctx.channel());
channelRead(ctx, Unpooled.wrappedBuffer(helloBytes)); channelRead(ctx, Unpooled.wrappedBuffer(helloBytes));
} else { } else {
logger.severefmt(promise.cause(), "Cannot finish handshake."); logger.atSevere().withCause(promise.cause()).log("Cannot finish handshake.");
ChannelFuture unusedFuture = ctx.close(); ChannelFuture unusedFuture = ctx.close();
} }
}); });

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import google.registry.proxy.metric.FrontendMetrics; import google.registry.proxy.metric.FrontendMetrics;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
@ -57,7 +57,7 @@ import java.util.function.Supplier;
*/ */
abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpResponse> { abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpResponse> {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Map<String, Cookie> cookieStore = new LinkedHashMap<>(); private final Map<String, Cookie> cookieStore = new LinkedHashMap<>();
private final String relayHost; private final String relayHost;
@ -162,7 +162,8 @@ abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpRespo
/** Terminates connection upon inbound exception. */ /** Terminates connection upon inbound exception. */
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.severefmt(cause, "Inbound exception caught for channel %s", ctx.channel()); logger.atSevere().withCause(cause).log(
"Inbound exception caught for channel %s", ctx.channel());
ChannelFuture unusedFuture = ctx.close(); ChannelFuture unusedFuture = ctx.close();
} }
@ -173,10 +174,8 @@ abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpRespo
promise.addListener( promise.addListener(
(ChannelFuture channelFuture) -> { (ChannelFuture channelFuture) -> {
if (!channelFuture.isSuccess()) { if (!channelFuture.isSuccess()) {
logger.severefmt( logger.atSevere().withCause(channelFuture.cause()).log(
channelFuture.cause(), "Outbound exception caught for channel %s", channelFuture.channel());
"Outbound exception caught for channel %s",
channelFuture.channel());
ChannelFuture unusedFuture = channelFuture.channel().close(); ChannelFuture unusedFuture = channelFuture.channel().close();
} }
}); });

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.US_ASCII;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
@ -56,7 +56,7 @@ public class ProxyProtocolHandler extends ByteToMessageDecoder {
public static final AttributeKey<String> REMOTE_ADDRESS_KEY = public static final AttributeKey<String> REMOTE_ADDRESS_KEY =
AttributeKey.valueOf("REMOTE_ADDRESS_KEY"); AttributeKey.valueOf("REMOTE_ADDRESS_KEY");
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
// The proxy header must start with this prefix. // The proxy header must start with this prefix.
// Sample header: "PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535\r\n". // Sample header: "PROXY TCP4 255.255.255.255 255.255.255.255 65535 65535\r\n".
@ -74,24 +74,24 @@ public class ProxyProtocolHandler extends ByteToMessageDecoder {
if (finished) { if (finished) {
String remoteIP; String remoteIP;
if (proxyHeader != null) { if (proxyHeader != null) {
logger.finefmt("PROXIED CONNECTION: %s", ctx.channel()); logger.atFine().log("PROXIED CONNECTION: %s", ctx.channel());
logger.finefmt("PROXY HEADER: %s", proxyHeader); logger.atFine().log("PROXY HEADER: %s", proxyHeader);
String[] headerArray = proxyHeader.split(" ", -1); String[] headerArray = proxyHeader.split(" ", -1);
if (headerArray.length == 6) { if (headerArray.length == 6) {
remoteIP = headerArray[2]; remoteIP = headerArray[2];
logger.finefmt("Header parsed, using %s as remote IP.", remoteIP); logger.atFine().log("Header parsed, using %s as remote IP.", remoteIP);
} else { } else {
logger.finefmt("Cannot parse the header, use source IP as a last resort."); logger.atFine().log("Cannot parse the header, use source IP as a last resort.");
remoteIP = getSourceIP(ctx); remoteIP = getSourceIP(ctx);
} }
} else { } else {
logger.finefmt("No header present, using source IP directly."); logger.atFine().log("No header present, using source IP directly.");
remoteIP = getSourceIP(ctx); remoteIP = getSourceIP(ctx);
} }
if (remoteIP != null) { if (remoteIP != null) {
ctx.channel().attr(REMOTE_ADDRESS_KEY).set(remoteIP); ctx.channel().attr(REMOTE_ADDRESS_KEY).set(remoteIP);
} else { } else {
logger.warningfmt("Not able to obtain remote IP for %s", ctx.channel()); logger.atWarning().log("Not able to obtain remote IP for %s", ctx.channel());
} }
// ByteToMessageDecoder automatically flushes unread bytes in the ByteBuf to the next handler // ByteToMessageDecoder automatically flushes unread bytes in the ByteBuf to the next handler
// when itself is being removed. // when itself is being removed.

View file

@ -16,7 +16,7 @@ package google.registry.proxy.handler;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -33,7 +33,7 @@ import javax.inject.Inject;
*/ */
public class RelayHandler<I> extends SimpleChannelInboundHandler<I> { public class RelayHandler<I> extends SimpleChannelInboundHandler<I> {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
/** Key used to retrieve the relay channel from a {@link Channel}'s {@link Attribute}. */ /** Key used to retrieve the relay channel from a {@link Channel}'s {@link Attribute}. */
public static final AttributeKey<Channel> RELAY_CHANNEL_KEY = public static final AttributeKey<Channel> RELAY_CHANNEL_KEY =
@ -46,7 +46,8 @@ public class RelayHandler<I> extends SimpleChannelInboundHandler<I> {
/** Terminate connection when an exception is caught during inbound IO. */ /** Terminate connection when an exception is caught during inbound IO. */
@Override @Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.severefmt(cause, "Inbound exception caught for channel %s", ctx.channel()); logger.atSevere().withCause(cause).log(
"Inbound exception caught for channel %s", ctx.channel());
ChannelFuture unusedFuture = ctx.close(); ChannelFuture unusedFuture = ctx.close();
} }

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static google.registry.proxy.Protocol.PROTOCOL_KEY; import static google.registry.proxy.Protocol.PROTOCOL_KEY;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import google.registry.proxy.HttpsRelayProtocolModule.HttpsRelayProtocol; import google.registry.proxy.HttpsRelayProtocolModule.HttpsRelayProtocol;
import google.registry.proxy.Protocol.BackendProtocol; import google.registry.proxy.Protocol.BackendProtocol;
import io.netty.channel.Channel; import io.netty.channel.Channel;
@ -45,14 +45,14 @@ import javax.net.ssl.SSLParameters;
@Sharable @Sharable
public class SslClientInitializer<C extends Channel> extends ChannelInitializer<C> { public class SslClientInitializer<C extends Channel> extends ChannelInitializer<C> {
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SslProvider sslProvider; private final SslProvider sslProvider;
private final X509Certificate[] trustedCertificates; private final X509Certificate[] trustedCertificates;
@Inject @Inject
SslClientInitializer( SslClientInitializer(
SslProvider sslProvider, @Nullable @HttpsRelayProtocol X509Certificate... trustCertificates) { SslProvider sslProvider, @Nullable @HttpsRelayProtocol X509Certificate... trustCertificates) {
logger.infofmt("Client SSL Provider: %s", sslProvider); logger.atInfo().log("Client SSL Provider: %s", sslProvider);
this.sslProvider = sslProvider; this.sslProvider = sslProvider;
this.trustedCertificates = trustCertificates; this.trustedCertificates = trustCertificates;
} }

View file

@ -14,7 +14,7 @@
package google.registry.proxy.handler; package google.registry.proxy.handler;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import google.registry.proxy.CertificateModule.EppCertificates; import google.registry.proxy.CertificateModule.EppCertificates;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler.Sharable; import io.netty.channel.ChannelHandler.Sharable;
@ -58,7 +58,7 @@ public class SslServerInitializer<C extends Channel> extends ChannelInitializer<
public static final AttributeKey<Promise<X509Certificate>> CLIENT_CERTIFICATE_PROMISE_KEY = public static final AttributeKey<Promise<X509Certificate>> CLIENT_CERTIFICATE_PROMISE_KEY =
AttributeKey.valueOf("CLIENT_CERTIFICATE_PROMISE_KEY"); AttributeKey.valueOf("CLIENT_CERTIFICATE_PROMISE_KEY");
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final SslProvider sslProvider; private final SslProvider sslProvider;
private final PrivateKey privateKey; private final PrivateKey privateKey;
private final X509Certificate[] certificates; private final X509Certificate[] certificates;
@ -68,7 +68,7 @@ public class SslServerInitializer<C extends Channel> extends ChannelInitializer<
SslProvider sslProvider, SslProvider sslProvider,
@EppCertificates PrivateKey privateKey, @EppCertificates PrivateKey privateKey,
@EppCertificates X509Certificate... certificates) { @EppCertificates X509Certificate... certificates) {
logger.infofmt("Server SSL Provider: %s", sslProvider); logger.atInfo().log("Server SSL Provider: %s", sslProvider);
this.sslProvider = sslProvider; this.sslProvider = sslProvider;
this.privateKey = privateKey; this.privateKey = privateKey;
this.certificates = certificates; this.certificates = certificates;

View file

@ -18,8 +18,8 @@ import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.api.services.monitoring.v3.model.MonitoredResource; import com.google.api.services.monitoring.v3.model.MonitoredResource;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.flogger.FluentLogger;
import com.google.common.io.CharStreams; import com.google.common.io.CharStreams;
import com.google.common.logging.FormattingLogger;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
@ -62,7 +62,7 @@ public class MetricParameters {
static final String INSTANCE_ID_PATH = "computeMetadata/v1/instance/id"; static final String INSTANCE_ID_PATH = "computeMetadata/v1/instance/id";
static final String ZONE_PATH = "computeMetadata/v1/instance/zone"; static final String ZONE_PATH = "computeMetadata/v1/instance/zone";
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
private final Map<String, String> envVarMap; private final Map<String, String> envVarMap;
private final Function<String, HttpURLConnection> connectionFactory; private final Function<String, HttpURLConnection> connectionFactory;
@ -88,8 +88,7 @@ public class MetricParameters {
connection.setDoOutput(true); connection.setDoOutput(true);
return connection; return connection;
} catch (IOException e) { } catch (IOException e) {
logger.warningfmt(e, "Incorrect GCE metadata server URL: %s", url); throw new RuntimeException(String.format("Incorrect GCE metadata server URL: %s", url), e);
throw new RuntimeException(e);
} }
} }
@ -104,7 +103,7 @@ public class MetricParameters {
connection.connect(); connection.connect();
int responseCode = connection.getResponseCode(); int responseCode = connection.getResponseCode();
if (responseCode < 200 || responseCode > 299) { if (responseCode < 200 || responseCode > 299) {
logger.warningfmt( logger.atWarning().log(
"Got an error response: %d\n%s", "Got an error response: %d\n%s",
responseCode, responseCode,
CharStreams.toString(new InputStreamReader(connection.getErrorStream(), UTF_8))); CharStreams.toString(new InputStreamReader(connection.getErrorStream(), UTF_8)));
@ -112,7 +111,7 @@ public class MetricParameters {
value = CharStreams.toString(new InputStreamReader(connection.getInputStream(), UTF_8)); value = CharStreams.toString(new InputStreamReader(connection.getInputStream(), UTF_8));
} }
} catch (IOException e) { } catch (IOException e) {
logger.warningfmt(e, "Cannot obtain GCE metadata from path %s", path); logger.atWarning().withCause(e).log("Cannot obtain GCE metadata from path %s", path);
} }
return value; return value;
} }
@ -124,7 +123,7 @@ public class MetricParameters {
String zone; String zone;
String[] fullZoneArray = fullZone.split("/", -1); String[] fullZoneArray = fullZone.split("/", -1);
if (fullZoneArray.length < 4) { if (fullZoneArray.length < 4) {
logger.warningfmt("Zone %s is valid.", fullZone); logger.atWarning().log("Zone %s is valid.", fullZone);
// This will make the metric report throw, but it happens in a different thread and will not // This will make the metric report throw, but it happens in a different thread and will not
// kill the whole application. // kill the whole application.
zone = ""; zone = "";

View file

@ -20,7 +20,7 @@ import static java.lang.StrictMath.min;
import com.google.auto.value.AutoValue; import com.google.auto.value.AutoValue;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.logging.FormattingLogger; import com.google.common.flogger.FluentLogger;
import google.registry.util.Clock; import google.registry.util.Clock;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -70,7 +70,7 @@ public class TokenStore {
T value; T value;
} }
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass(); private static final FluentLogger logger = FluentLogger.forEnclosingClass();
/** A map of {@code userId} to available tokens, timestamped at last refill time. */ /** A map of {@code userId} to available tokens, timestamped at last refill time. */
private final ConcurrentHashMap<String, TimestampedInteger> tokensMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String, TimestampedInteger> tokensMap = new ConcurrentHashMap<>();
@ -201,7 +201,7 @@ public class TokenStore {
refreshExecutor.scheduleWithFixedDelay( refreshExecutor.scheduleWithFixedDelay(
() -> { () -> {
refresh(); refresh();
logger.infofmt("Refreshing quota for protocol %s", config.getProtocolName()); logger.atInfo().log("Refreshing quota for protocol %s", config.getProtocolName());
}, },
config.getRefreshPeriod().getStandardSeconds(), config.getRefreshPeriod().getStandardSeconds(),
config.getRefreshPeriod().getStandardSeconds(), config.getRefreshPeriod().getStandardSeconds(),