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
This commit is contained in:
Robert Muir 2013-07-02 13:34:12 +00:00
parent c100f376f0
commit 7b5c09d061
8 changed files with 129 additions and 8 deletions

View File

@ -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
----------------------

View File

@ -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 {}
}

View File

@ -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();

View File

@ -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>

View File

@ -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);
}
}

View File

@ -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>

View File

@ -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

View File

@ -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>