From 7b5c09d0619fb18a942ddf690dd4e7a9bcff50f2 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 2 Jul 2013 13:34:12 +0000 Subject: [PATCH] SOLR-4977: Add option to send infostream to the logging system git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1498936 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 ++ .../apache/solr/update/LoggingInfoStream.java | 45 +++++++++++++++++++ .../apache/solr/update/SolrIndexConfig.java | 8 +++- .../conf/solrconfig-infostream-logging.xml | 27 +++++++++++ .../solr/core/TestInfoStreamLogging.java | 38 ++++++++++++++++ solr/example/alt-configs/hdfs/solrconfig.xml | 6 +-- solr/example/resources/log4j.properties | 3 ++ .../solr/collection1/conf/solrconfig.xml | 7 +-- 8 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 solr/core/src/java/org/apache/solr/update/LoggingInfoStream.java create mode 100644 solr/core/src/test-files/solr/collection1/conf/solrconfig-infostream-logging.xml create mode 100644 solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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 that new 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.java new file mode 100644 index 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.java index 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 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.xml new file mode 100644 index 00000000000..722f5e42265 --- /dev/null +++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-infostream-logging.xml @@ -0,0 +1,27 @@ + + + + + ${solr.data.dir:} + + ${tests.luceneMatchVersion:LUCENE_CURRENT} + + + true + + diff --git a/solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java b/solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java new file mode 100644 index 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.xml index 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. --> - + diff --git a/solr/example/resources/log4j.properties b/solr/example/resources/log4j.properties index 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=WARN log4j.logger.org.apache.hadoop=WARN + +# set to INFO to enable infostream log messages +log4j.logger.org.apache.solr.update.LoggingInfoStream=OFF diff --git a/solr/example/solr/collection1/conf/solrconfig.xml b/solr/example/solr/collection1/conf/solrconfig.xml index 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. --> - + true