From 9e09045a4c61a8d35b994adadd8f283add10cba7 Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Thu, 22 Sep 2016 09:33:11 +0200 Subject: [PATCH] SOLR-8186: suppress log4j access warnings. --- .../solr/servlet/SolrDispatchFilter.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java index bbcd61508a3..0c3a2f3e57b 100644 --- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java +++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java @@ -56,6 +56,7 @@ import org.apache.solr.common.SolrException; import org.apache.solr.common.SolrException.ErrorCode; import org.apache.solr.common.cloud.SolrZkClient; import org.apache.solr.common.util.ExecutorUtil; +import org.apache.solr.common.util.SuppressForbidden; import org.apache.solr.core.CoreContainer; import org.apache.solr.core.NodeConfig; import org.apache.solr.core.SolrCore; @@ -123,14 +124,7 @@ public class SolrDispatchFilter extends BaseSolrFilter { { String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE); if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) { - Enumeration appenders = LogManager.getRootLogger().getAllAppenders(); - while (appenders.hasMoreElements()) { - Appender appender = (Appender) appenders.nextElement(); - if (appender instanceof ConsoleAppender) { - log.info("Property solr.log.muteconsole given. Muting ConsoleAppender named " + appender.getName()); - LogManager.getRootLogger().removeAppender(appender); - } - } + muteConsole(); } log.info("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader()); @@ -167,6 +161,18 @@ public class SolrDispatchFilter extends BaseSolrFilter { log.info("SolrDispatchFilter.init() done"); } + @SuppressForbidden(reason = "Legitimate log4j access") + private void muteConsole() { + Enumeration appenders = LogManager.getRootLogger().getAllAppenders(); + while (appenders.hasMoreElements()) { + Appender appender = (Appender) appenders.nextElement(); + if (appender instanceof ConsoleAppender) { + log.info("Property solr.log.muteconsole given. Muting ConsoleAppender named " + appender.getName()); + LogManager.getRootLogger().removeAppender(appender); + } + } + } + /** * Override this to change CoreContainer initialization * @return a CoreContainer to hold this server's cores