Log source IP when logging is enabled

We will only enable logging for non-production environment, so there shouldn't be any privacy concerns by enabling this.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198744739
This commit is contained in:
jianglai 2018-05-31 10:48:33 -07:00 committed by Ben McIlwain
parent af8b050446
commit 3960207502
2 changed files with 18 additions and 10 deletions

View file

@ -38,6 +38,7 @@ import google.registry.proxy.HealthCheckProtocolModule.HealthCheckProtocol;
import google.registry.proxy.Protocol.FrontendProtocol; import google.registry.proxy.Protocol.FrontendProtocol;
import google.registry.proxy.ProxyConfig.Environment; import google.registry.proxy.ProxyConfig.Environment;
import google.registry.proxy.WhoisProtocolModule.WhoisProtocol; import google.registry.proxy.WhoisProtocolModule.WhoisProtocol;
import google.registry.proxy.handler.ProxyProtocolHandler;
import google.registry.util.Clock; import google.registry.util.Clock;
import google.registry.util.SystemClock; import google.registry.util.SystemClock;
import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LogLevel;
@ -103,6 +104,19 @@ public class ProxyModule {
rootHandler.setFormatter(new GcpJsonFormatter()); rootHandler.setFormatter(new GcpJsonFormatter());
} }
rootLoggerConfig.addHandler(rootHandler); rootLoggerConfig.addHandler(rootHandler);
if (log) {
// The LoggingHandler records logs at LogLevel.DEBUG (internal Netty log level), which
// corresponds to Level.FINE (JUL log level). It uses a JUL logger with the name
// "io.netty.handler.logging.LoggingHandler" to actually process the logs. This JUL logger is
// set to Level.FINE if the --log parameter is passed, so that it does not filter out logs
// that the LoggingHandler writes. Otherwise the logs are silently ignored because the default
// JUL logger level is Level.INFO.
LoggerConfig.getConfig(LoggingHandler.class).setLevel(Level.FINE);
// Log source IP information if --log parameter is passed. This is considered PII and should
// only be used in non-production environment for debugging purpose.
LoggerConfig.getConfig(ProxyProtocolHandler.class).setLevel(Level.FINE);
}
} }
/** /**
@ -156,19 +170,13 @@ public class ProxyModule {
/** /**
* Provides shared logging handler. * Provides shared logging handler.
* *
* <p>The {@link LoggingHandler} records logs at {@code LogLevel.DEBUG} (internal Netty log * <p>Note that this handler always records logs at {@code LogLevel.DEBUG}, it is up to the JUL
* level), which corresponds to {@code Level.FINE} (JUL log level). It uses a JUL logger called * logger that it contains to decide if logs at this level should actually be captured. The log
* {@code io.netty.handler.logging.LoggingHandler} to actually process the logs. This logger is * level of the JUL logger is configured in {@link #configureLogging()}.
* set to {@code Level.FINE} if {@code --log} parameter is passed, so that it does not filter out
* logs that the {@link LoggingHandler} captures. Otherwise the logs are silently ignored because
* the default logger level is {@code Level.INFO}.
*/ */
@Singleton @Singleton
@Provides @Provides
LoggingHandler provideLoggingHandler() { LoggingHandler provideLoggingHandler() {
if (log) {
LoggerConfig.getConfig(io.netty.handler.logging.LoggingHandler.class).setLevel(Level.FINE);
}
return new LoggingHandler(LogLevel.DEBUG); return new LoggingHandler(LogLevel.DEBUG);
} }

View file

@ -203,7 +203,7 @@ public class ProxyServer implements Runnable {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// Use JDK logger for Netty's LoggingHandler, // Use JDK logger for Netty's LoggingHandler,
// which is what google.registry.util.FormattingLog uses under the hood. // which is what Flogger uses under the hood.
InternalLoggerFactory.setDefaultFactory(JdkLoggerFactory.INSTANCE); InternalLoggerFactory.setDefaultFactory(JdkLoggerFactory.INSTANCE);
// Configure the components, this needs to run first so that the logging format is properly // Configure the components, this needs to run first so that the logging format is properly