diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-22 21:09:45 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-09-27 12:29:27 +0200 |
commit | 7ed36fc7a331927153f99adf9683b5fe995851ea (patch) | |
tree | d57b0f9e4d9e45e07606b0454a40daf3bb39e99c /server/sonar-process/src | |
parent | 0d6868ad3bee64df7020d2b0a72b4dcdb90e0a3f (diff) | |
download | sonarqube-7ed36fc7a331927153f99adf9683b5fe995851ea.tar.gz sonarqube-7ed36fc7a331927153f99adf9683b5fe995851ea.zip |
SONAR-6799 SONAR-6232 compute engine logs
- add WS api/ce/logs
- add boolean field 'logs' to the responses of the WS that return tasks
- purge log files (max nb of files per project can be configured)
Diffstat (limited to 'server/sonar-process/src')
-rw-r--r-- | server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java | 10 | ||||
-rw-r--r-- | server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java | 19 |
2 files changed, 22 insertions, 7 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java b/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java index 6afcbfa1738..0d5d3551872 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java +++ b/server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java @@ -29,16 +29,17 @@ import ch.qos.logback.classic.spi.LoggerContextListener; import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.Context; import ch.qos.logback.core.FileAppender; +import ch.qos.logback.core.filter.Filter; import ch.qos.logback.core.joran.spi.JoranException; import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; import ch.qos.logback.core.rolling.RollingFileAppender; import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; +import java.io.File; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; import org.slf4j.LoggerFactory; -import java.io.File; - /** * Helps to configure Logback in a programmatic way, without using XML. */ @@ -72,7 +73,7 @@ public class LogbackHelper { return propagator; } - public ConsoleAppender newConsoleAppender(Context loggerContext, String name, String pattern) { + public ConsoleAppender newConsoleAppender(Context loggerContext, String name, String pattern, @Nullable Filter filter) { PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder(); consoleEncoder.setContext(loggerContext); consoleEncoder.setPattern(pattern); @@ -82,6 +83,9 @@ public class LogbackHelper { consoleAppender.setEncoder(consoleEncoder); consoleAppender.setName(name); consoleAppender.setTarget("System.out"); + if (filter != null) { + consoleAppender.addFilter(filter); + } consoleAppender.start(); return consoleAppender; } diff --git a/server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java b/server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java index 5d63c90350c..1cd17d936bf 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java @@ -27,21 +27,22 @@ import ch.qos.logback.classic.spi.LoggerContextListener; import ch.qos.logback.core.Appender; import ch.qos.logback.core.ConsoleAppender; import ch.qos.logback.core.FileAppender; +import ch.qos.logback.core.filter.Filter; import ch.qos.logback.core.rolling.FixedWindowRollingPolicy; import ch.qos.logback.core.rolling.RollingFileAppender; import ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy; import ch.qos.logback.core.rolling.TimeBasedRollingPolicy; +import java.io.File; +import java.util.Properties; import org.junit.AfterClass; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import java.io.File; -import java.util.Properties; - import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; public class LogbackHelperTest { @@ -81,12 +82,22 @@ public class LogbackHelperTest { @Test public void newConsoleAppender() { LoggerContext ctx = underTest.getRootContext(); - ConsoleAppender<?> appender = underTest.newConsoleAppender(ctx, "MY_APPENDER", "%msg%n"); + ConsoleAppender<?> appender = underTest.newConsoleAppender(ctx, "MY_APPENDER", "%msg%n", null); assertThat(appender.getName()).isEqualTo("MY_APPENDER"); assertThat(appender.getContext()).isSameAs(ctx); assertThat(appender.isStarted()).isTrue(); assertThat(((PatternLayoutEncoder) appender.getEncoder()).getPattern()).isEqualTo("%msg%n"); + assertThat(appender.getCopyOfAttachedFiltersList()).isEmpty(); + } + + @Test + public void newConsoleAppender_with_filter() { + Filter filter = mock(Filter.class); + LoggerContext ctx = underTest.getRootContext(); + ConsoleAppender<?> appender = underTest.newConsoleAppender(ctx, "MY_APPENDER", "%msg%n", filter); + + assertThat(appender.getCopyOfAttachedFiltersList()).containsOnly(filter); } @Test |