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

@ -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.util.X509Utils.getCertificateHash;
import com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import google.registry.proxy.metric.FrontendMetrics;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -40,7 +40,7 @@ import java.util.function.Supplier;
/** Handler that processes EPP protocol logic. */
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
@ -118,7 +118,7 @@ public class EppServiceHandler extends HttpsRelayServiceHandler {
"epp", sslClientCertificateHash, ctx.channel());
channelRead(ctx, Unpooled.wrappedBuffer(helloBytes));
} else {
logger.severefmt(promise.cause(), "Cannot finish handshake.");
logger.atSevere().withCause(promise.cause()).log("Cannot finish handshake.");
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 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 io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelFuture;
@ -57,7 +57,7 @@ import java.util.function.Supplier;
*/
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 String relayHost;
@ -162,7 +162,8 @@ abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpRespo
/** Terminates connection upon inbound exception. */
@Override
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();
}
@ -173,10 +174,8 @@ abstract class HttpsRelayServiceHandler extends ByteToMessageCodec<FullHttpRespo
promise.addListener(
(ChannelFuture channelFuture) -> {
if (!channelFuture.isSuccess()) {
logger.severefmt(
channelFuture.cause(),
"Outbound exception caught for channel %s",
channelFuture.channel());
logger.atSevere().withCause(channelFuture.cause()).log(
"Outbound exception caught for channel %s", channelFuture.channel());
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 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.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
@ -56,7 +56,7 @@ public class ProxyProtocolHandler extends ByteToMessageDecoder {
public static final AttributeKey<String> 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.
// 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) {
String remoteIP;
if (proxyHeader != null) {
logger.finefmt("PROXIED CONNECTION: %s", ctx.channel());
logger.finefmt("PROXY HEADER: %s", proxyHeader);
logger.atFine().log("PROXIED CONNECTION: %s", ctx.channel());
logger.atFine().log("PROXY HEADER: %s", proxyHeader);
String[] headerArray = proxyHeader.split(" ", -1);
if (headerArray.length == 6) {
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 {
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);
}
} else {
logger.finefmt("No header present, using source IP directly.");
logger.atFine().log("No header present, using source IP directly.");
remoteIP = getSourceIP(ctx);
}
if (remoteIP != null) {
ctx.channel().attr(REMOTE_ADDRESS_KEY).set(remoteIP);
} 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
// 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 com.google.common.logging.FormattingLogger;
import com.google.common.flogger.FluentLogger;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
@ -33,7 +33,7 @@ import javax.inject.Inject;
*/
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}. */
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. */
@Override
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();
}

View file

@ -17,7 +17,7 @@ package google.registry.proxy.handler;
import static com.google.common.base.Preconditions.checkNotNull;
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.Protocol.BackendProtocol;
import io.netty.channel.Channel;
@ -45,14 +45,14 @@ import javax.net.ssl.SSLParameters;
@Sharable
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 X509Certificate[] trustedCertificates;
@Inject
SslClientInitializer(
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.trustedCertificates = trustCertificates;
}

View file

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