Block config logging from known Jersey suspects
Config log level is enabled by default in Vespa, while it's not in Java
logging API. This results in a lot of unintentional noise from 3rd party libraries in our
Vespa log.
@@ -10,7 +10,9 @@ import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
+import java.util.List;
import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -22,7 +24,7 @@ import static java.util.logging.Level.CONFIG;
*
* Notes:
* - hostname verification is not enabled - CN/SAN verification is assumed to be handled by the underlying x509 trust manager.
- * - ssl context or hostname verifier must not be overriden by the caller
+ * - ssl context or hostname verifier must not be overridden by the caller
*
* @author bjorncs
*/
@@ -30,23 +32,28 @@ public class VespaClientBuilderFactory implements AutoCloseable {
private static final Logger log = Logger.getLogger(VespaClientBuilderFactory.class.getName());
+ // Keep instances of the Jersey loggers to block the JVM from GCing them in case we initialize the loggers before
+ // their owner classes (e.g ExecutorProviders) are loaded.
+ private static final List<Logger> externalJerseyLoggers = new CopyOnWriteArrayList<>();
+
static {
// CONFIG log message are logged repeatedly from these classes.
disableConfigLogging("org.glassfish.jersey.client.internal.HttpUrlConnector");
disableConfigLogging("org.glassfish.jersey.process.internal.ExecutorProviders");
+ disableConfigLogging("athenz.shade.zts.org.glassfish.jersey.client.internal.HttpUrlConnector");
+ disableConfigLogging("athenz.shade.zts.org.glassfish.jersey.process.internal.ExecutorProviders");
}
- // This method will hook a filter into the Jersey logger removing unwanted messages.
+ // This method will hook a filter into the Jersey logger removing unwanted config messages.
private static void disableConfigLogging(String className) {
@SuppressWarnings("LoggerInitializedWithForeignClass")
Logger logger = Logger.getLogger(className);
Optional<Filter> currentFilter = Optional.ofNullable(logger.getFilter());
Filter filter = logRecord ->
- !logRecord.getMessage().startsWith("Restricted headers are not enabled")
- && !logRecord.getMessage().startsWith("Selected ExecutorServiceProvider implementation")
- && !logRecord.getLevel().equals(CONFIG)
+ !logRecord.getLevel().equals(CONFIG)
&& currentFilter.map(f -> f.isLoggable(logRecord)).orElse(true); // Honour existing filter if exists
logger.setFilter(filter);
+ externalJerseyLoggers.add(logger);
}
