]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8148 do not log data and decrease log level to debug
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 30 Sep 2016 21:10:28 +0000 (23:10 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 30 Sep 2016 21:10:28 +0000 (23:10 +0200)
sonar-db/src/main/java/org/sonar/db/version/v51/FeedFileSourcesBinaryData.java
sonar-db/src/test/java/org/sonar/db/version/v51/FeedFileSourcesBinaryDataTest.java

index 22c5f649e8390bc55fdac46e0eded16fcaa57c51..9a6f23047e756c5d69ffa66e7b3670d4a80b6b8b 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.db.version.v51;
 
 import com.google.common.base.Function;
 import com.google.common.base.Splitter;
+import com.google.common.base.Throwables;
 import com.google.common.collect.Iterables;
 import java.sql.SQLException;
 import java.util.Date;
@@ -148,8 +149,8 @@ public class FeedFileSourcesBinaryData extends BaseDataChange {
       }
       return FileSourceDto.encodeSourceData(dataBuilder.build());
     } catch (Exception e) {
-      Loggers.get(FeedFileSourcesBinaryData.class).error(
-        String.format("Invalid FILE_SOURCES.DATA on row with ID %s, data will be ignored: %s", fileSourceId, data), e);
+      Loggers.get(FeedFileSourcesBinaryData.class).debug(
+        "Invalid FILE_SOURCES.DATA on row with ID {}, data will be ignored. {}", fileSourceId, Throwables.getStackTraceAsString(e));
       return FileSourceDto.encodeSourceData(dataBuilder.clear().build());
     } finally {
       IOUtils.closeQuietly(parser);
index 836291c23d3aebe4c03a92534bb1b465ea911f57..d96d67b6ac7d4e725d55ac6e27081318fd803f8e 100644 (file)
@@ -23,11 +23,14 @@ import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.List;
 import org.apache.commons.dbutils.DbUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.sonar.api.utils.System2;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.db.DbTester;
 import org.sonar.db.protobuf.DbFileSources;
 import org.sonar.db.source.FileSourceDto;
@@ -43,6 +46,9 @@ public class FeedFileSourcesBinaryDataTest {
   @Rule
   public DbTester db = DbTester.createForSchema(System2.INSTANCE, FeedFileSourcesBinaryDataTest.class, "schema.sql");
 
+  @Rule
+  public LogTester logTester = new LogTester().setLevel(LoggerLevel.DEBUG);
+
   @Test
   public void convert_csv_to_protobuf() throws Exception {
     db.prepareDbUnit(getClass(), "data.xml");
@@ -79,6 +85,9 @@ public class FeedFileSourcesBinaryDataTest {
       DbFileSources.Data data = selectData(connection, 1L);
 
       assertThat(data.getLinesList()).isEmpty();
+      List<String> debugLogs = logTester.logs(LoggerLevel.DEBUG);
+      assertThat(debugLogs.stream()
+        .anyMatch(s -> s.startsWith("Invalid FILE_SOURCES.DATA on row with ID 1, data will be ignored"))).isTrue();
     }
   }