Apache Lucene open-source search software
SOLR-4977: Add option to send infostream to the logging system
Robert Muir7b5c09d0619f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex a8078046ba1..9e798c37eeb 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -145,6 +145,9 @@ New Features* SOLR-4655: Add option to have Overseer assign generic node names so thatnew addresses can host shards without naming confusion. (Mark Miller, Anshum Gupta)+* SOLR-4977: Add option to send IndexWriter's infostream to the logging system.+ (Ryan Ernst via Robert Muir)+Bug Fixes----------------------diff --git a/solr/core/src/java/org/apache/solr/update/LoggingInfoStream.java b/solr/core/src/java/org/apache/solr/update/LoggingInfoStream.javanew file mode 100644index 00000000000..e710c0a4a7c--- /dev/null+++ b/solr/core/src/java/org/apache/solr/update/LoggingInfoStream.java@@ -0,0 +1,45 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.update;++import org.apache.lucene.util.InfoStream;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import java.io.IOException;++/**+ * An {@link InfoStream} implementation which passes messages on to Solr's logging.+ */+public class LoggingInfoStream extends InfoStream {+ public static final Logger log = LoggerFactory.getLogger(LoggingInfoStream.class);++ @Override+ public void message(String component, String message) {+ log.info("[" + component + "][" + Thread.currentThread().getName() + "]: " + message);+ }++ @Override+ public boolean isEnabled(String component) {+ // ignore testpoints so this can be used with tests without flooding logs with verbose messages+ return !"TP".equals(component) && log.isInfoEnabled();+ }++ @Override+ public void close() throws IOException {}+}diff --git a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.javaindex 0a5f0555b97..adef372522c 100644--- a/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java+++ b/solr/core/src/java/org/apache/solr/update/SolrIndexConfig.java@@ -153,8 +153,12 @@ public class SolrIndexConfig {boolean infoStreamEnabled = solrConfig.getBool(prefix + "/infoStream", false);if(infoStreamEnabled) {String infoStreamFile = solrConfig.get(prefix + "/infoStream/@file", null);- if (infoStreamFile != null) {- log.info("IndexWriter infoStream debug log is enabled: " + infoStreamFile);+ if (infoStreamFile == null) {+ log.info("IndexWriter infoStream solr logging is enabled");+ infoStream = new LoggingInfoStream();+ } else {+ log.warn("IndexWriter infoStream file log is enabled: " + infoStreamFile ++ "\nThis feature is deprecated. Remove @file from <infoStream> to output messages to solr's logfile");File f = new File(infoStreamFile);File parent = f.getParentFile();if (parent != null) parent.mkdirs();diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-infostream-logging.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-infostream-logging.xmlnew file mode 100644index 00000000000..722f5e42265--- /dev/null+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-infostream-logging.xml@@ -0,0 +1,27 @@+<?xml version="1.0" ?>++<!--+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+-->+<config>+ <dataDir>${solr.data.dir:}</dataDir>++ <luceneMatchVersion>${tests.luceneMatchVersion:LUCENE_CURRENT}</luceneMatchVersion>++ <indexConfig>+ <infoStream>true</infoStream>+ </indexConfig>+</config>diff --git a/solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java b/solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.javanew file mode 100644index 00000000000..fa6bc3fd852--- /dev/null+++ b/solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java@@ -0,0 +1,38 @@+package org.apache.solr.core;++/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import org.apache.lucene.index.IndexWriterConfig;+import org.apache.lucene.util.PrintStreamInfoStream;+import org.apache.solr.SolrTestCaseJ4;+import org.apache.solr.update.LoggingInfoStream;+import org.junit.BeforeClass;++public class TestInfoStreamLogging extends SolrTestCaseJ4 {++ @BeforeClass+ public static void beforeClass() throws Exception {+ initCore("solrconfig-infostream-logging.xml","schema.xml");+ }++ public void testIndexConfig() throws Exception {+ IndexWriterConfig iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore().getLatestSchema());++ assertTrue(iwc.getInfoStream() instanceof LoggingInfoStream);+ }+}diff --git a/solr/example/alt-configs/hdfs/solrconfig.xml b/solr/example/alt-configs/hdfs/solrconfig.xmlindex 7a5d28fb220..3fa0463d814 100644--- a/solr/example/alt-configs/hdfs/solrconfig.xml+++ b/solr/example/alt-configs/hdfs/solrconfig.xml@@ -298,10 +298,10 @@To aid in advanced debugging, Lucene provides an "InfoStream"of detailed information when indexing.- Setting The value to true will instruct the underlying Lucene- IndexWriter to write its debugging info the specified file+ Setting the value to true will instruct the underlying Lucene+ IndexWriter to write its info stream to solr's log.-->- <!-- <infoStream file="INFOSTREAM.txt">false</infoStream> -->+ <!-- <infoStream>false</infoStream> --></indexConfig>diff --git a/solr/example/resources/log4j.properties b/solr/example/resources/log4j.propertiesindex d9becb605d6..f33fa719f8d 100644--- a/solr/example/resources/log4j.properties+++ b/solr/example/resources/log4j.properties@@ -19,3 +19,6 @@ log4j.appender.file.layout.ConversionPattern=%-5p - %d{yyyy-MM-dd HH:mm:ss.SSS};log4j.logger.org.apache.zookeeper=WARNlog4j.logger.org.apache.hadoop=WARN++# set to INFO to enable infostream log messages+log4j.logger.org.apache.solr.update.LoggingInfoStream=OFFdiff --git a/solr/example/solr/collection1/conf/solrconfig.xml b/solr/example/solr/collection1/conf/solrconfig.xmlindex f1d5486c349..2ed3181a02d 100755--- a/solr/example/solr/collection1/conf/solrconfig.xml+++ b/solr/example/solr/collection1/conf/solrconfig.xml@@ -304,10 +304,11 @@To aid in advanced debugging, Lucene provides an "InfoStream"of detailed information when indexing.- Setting The value to true will instruct the underlying Lucene- IndexWriter to write its debugging info the specified file+ Setting the value to true will instruct the underlying Lucene+ IndexWriter to write its info stream to solr's log. By default,+ this is enabled here, and controlled through log4j.properties.-->- <!-- <infoStream file="INFOSTREAM.txt">false</infoStream> -->+ <infoStream>true</infoStream></indexConfig>