diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index d0e4537bc5c..b0de132b87c 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -176,6 +176,9 @@ New Features * SOLR-5682: Make the admin InfoHandler more pluggable / derivable. (Greg Chanan via Mark Miller) +* SOLR-5672: Add logParamsList parameter to support reduced logging. + (Christine Poerschke via Mark Miller) + Bug Fixes ---------------------- diff --git a/solr/core/src/java/org/apache/solr/core/SolrCore.java b/solr/core/src/java/org/apache/solr/core/SolrCore.java index 8770edd8005..44d0cb218d5 100644 --- a/solr/core/src/java/org/apache/solr/core/SolrCore.java +++ b/solr/core/src/java/org/apache/solr/core/SolrCore.java @@ -24,6 +24,7 @@ import java.io.InputStreamReader; import java.io.Writer; import java.lang.reflect.Constructor; import java.net.URL; +import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1932,7 +1933,14 @@ public final class SolrCore implements SolrInfoMBean { // are expecting them during handleRequest toLog.add("webapp", req.getContext().get("webapp")); toLog.add("path", req.getContext().get("path")); - toLog.add("params", "{" + req.getParamString() + "}"); + + final SolrParams params = req.getParams(); + final String lpList = params.get(CommonParams.LOG_PARAMS_LIST); + if (lpList == null) { + toLog.add("params", "{" + req.getParamString() + "}"); + } else if (lpList.length() > 0) { + toLog.add("params", "{" + params.toFilteredSolrParams(Arrays.asList(lpList.split(","))).toString() + "}"); + } } /** Put status, QTime, and possibly request handler and params, in the response header */ diff --git a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java index c7d1f5f20b9..396e7992632 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java @@ -181,6 +181,9 @@ public interface CommonParams { } }; + /** which parameters to log (if not supplied all parameters will be logged) **/ + public static final String LOG_PARAMS_LIST = "logParamsList"; + public static final String EXCLUDE = "ex"; public static final String TAG = "tag"; public static final String TERMS = "terms"; diff --git a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java index bf91cb39255..02501d2259c 100644 --- a/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java +++ b/solr/solrj/src/java/org/apache/solr/common/params/SolrParams.java @@ -20,6 +20,7 @@ package org.apache.solr.common.params; import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.apache.solr.common.SolrException; @@ -298,6 +299,21 @@ public abstract class SolrParams implements Serializable { return new MapSolrParams(map); } + /** Create filtered SolrParams. */ + public SolrParams toFilteredSolrParams(List names) { + NamedList nl = new NamedList(); + for (Iterator it = getParameterNamesIterator(); it.hasNext();) { + final String name = it.next(); + if (names.contains(name)) { + final String[] values = getParams(name); + for (String value : values) { + nl.add(name, value); + } + } + } + return toSolrParams(nl); + } + /** Convert this to a NamedList */ public NamedList toNamedList() { final SimpleOrderedMap result = new SimpleOrderedMap(); @@ -315,11 +331,3 @@ public abstract class SolrParams implements Serializable { return result; } } - - - - - - - -