]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8837 add indexing time to logs
authorDaniel Schwarz <daniel.schwarz@sonarsource.com>
Mon, 27 Feb 2017 20:31:40 +0000 (21:31 +0100)
committerDaniel Schwarz <bartfastiel@users.noreply.github.com>
Wed, 1 Mar 2017 16:48:14 +0000 (17:48 +0100)
server/sonar-server/src/main/java/org/sonar/server/es/IndexerStartupTask.java

index d5d1d1a527a8db5316b75cd3863a897a36fcb2fd..8dd11f94d322e93fb3129e967ebde6dc76584591 100644 (file)
@@ -30,6 +30,7 @@ import org.elasticsearch.common.unit.TimeValue;
 import org.sonar.api.config.Settings;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
+import org.sonar.api.utils.log.Profiler;
 
 import static java.util.Arrays.stream;
 import static java.util.stream.Collectors.toSet;
@@ -63,10 +64,11 @@ public class IndexerStartupTask {
   private void indexEmptyTypes(StartupIndexer indexer) {
     Set<IndexType> uninizializedTypes = getUninitializedTypes(indexer);
     if (!uninizializedTypes.isEmpty()) {
-      log(uninizializedTypes, "...");
+      Profiler profiler = Profiler.create(LOG);
+      profiler.startInfo(getLogMessage(uninizializedTypes, "..."));
       indexer.indexOnStartup(uninizializedTypes);
       uninizializedTypes.forEach(this::setInitialized);
-      log(uninizializedTypes, "done");
+      profiler.stopInfo(getLogMessage(uninizializedTypes, "done"));
     }
   }
 
@@ -113,9 +115,9 @@ public class IndexerStartupTask {
     return "index." + SETTING_PREFIX_INITIAL_INDEXING_FINISHED + indexType.getType();
   }
 
-  private void log(Set<IndexType> emptyTypes, String suffix) {
+  private String getLogMessage(Set<IndexType> emptyTypes, String suffix) {
     String s = emptyTypes.size() == 1 ? "" : "s";
     String typeList = emptyTypes.stream().map(Object::toString).collect(Collectors.joining(","));
-    LOG.info("Full indexing of type{} {} {}", s, typeList, suffix);
+    return String.format("Indexing of type%s %s %s", s, typeList, suffix);
   }
 }