Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/SOLR-5505-infostream-core-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
title: "LoggingInfoStream (IndexWriter infoStream logging) now includes the core name in every message so multi-core logs can be told apart"
type: changed
authors:
- name: Nick Shanin
links:
- name: SOLR-5505
url: https://issues.apache.org/jira/browse/SOLR-5505
21 changes: 19 additions & 2 deletions solr/core/src/java/org/apache/solr/update/LoggingInfoStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,27 @@
public class LoggingInfoStream extends InfoStream {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private final String coreName;

public LoggingInfoStream() {
this(null);
}

/**
* @param coreName if not null, the name of the core is added to every message
*/
public LoggingInfoStream(String coreName) {
this.coreName = coreName;
}

@Override
public void message(String component, String message) {
if (log.isInfoEnabled()) {
log.info("[{}][{}]: {}", component, Thread.currentThread().getName(), message);
if (coreName == null) {
if (log.isInfoEnabled()) {
log.info("[{}][{}]: {}", component, Thread.currentThread().getName(), message);
}
} else if (log.isInfoEnabled()) {
log.info("[{}][{}][{}]: {}", coreName, component, Thread.currentThread().getName(), message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ public IndexWriterConfig toIndexWriterConfig(SolrCore core) throws IOException {
iwc.setMergePolicy(mergePolicy);
MergeScheduler mergeScheduler = buildMergeScheduler(core.getResourceLoader());
iwc.setMergeScheduler(mergeScheduler);
iwc.setInfoStream(infoStream);
// one config is shared by reloads and may not know its core, so tag the stream per core here
iwc.setInfoStream(
infoStream instanceof LoggingInfoStream
? new LoggingInfoStream(core.getName())
: infoStream);

if (mergePolicy instanceof SortingMergePolicy) {
Sort indexSort = ((SortingMergePolicy) mergePolicy).getSort();
Expand Down
12 changes: 12 additions & 0 deletions solr/core/src/test/org/apache/solr/core/TestInfoStreamLogging.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
package org.apache.solr.core;

import static org.hamcrest.Matchers.containsString;

import org.apache.lucene.index.IndexWriterConfig;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.update.LoggingInfoStream;
import org.apache.solr.util.LogListener;
import org.junit.BeforeClass;

public class TestInfoStreamLogging extends SolrTestCaseJ4 {
Expand All @@ -33,4 +36,13 @@ public void testIndexConfig() throws Exception {

assertTrue(iwc.getInfoStream() instanceof LoggingInfoStream);
}

public void testMessagesNameTheCore() throws Exception {
IndexWriterConfig iwc = solrConfig.indexConfig.toIndexWriterConfig(h.getCore());

try (LogListener listener = LogListener.info(LoggingInfoStream.class)) {
iwc.getInfoStream().message("IW", "hello from the stream");
assertThat(listener.pollMessage(), containsString("[" + h.getCore().getName() + "][IW]"));
}
}
}
Loading