aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-search
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-11-09 16:23:46 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-11-16 10:09:21 +0100
commitadf8fbe5364084c3da6d004d1ad55cba0620be4d (patch)
tree3e466cd1a58786bcac15054988f1c781f567e496 /server/sonar-search
parent38242dc18f85afbf8a134ffbe48be5cf8e98eceb (diff)
downloadsonarqube-adf8fbe5364084c3da6d004d1ad55cba0620be4d.tar.gz
sonarqube-adf8fbe5364084c3da6d004d1ad55cba0620be4d.zip
SONAR-8333 make ES log into its own log file
Diffstat (limited to 'server/sonar-search')
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java14
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchServer.java2
-rw-r--r--server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java45
3 files changed, 45 insertions, 16 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java b/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java
index ec3ac8fc78b..174733eb097 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java
@@ -19,26 +19,20 @@
*/
package org.sonar.search;
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.ConsoleAppender;
import org.sonar.process.LogbackHelper;
+import org.sonar.process.Props;
public class SearchLogging {
- private static final String LOG_FORMAT = "%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{20}] %X %msg%n";
-
private LogbackHelper helper = new LogbackHelper();
- public LoggerContext configure() {
+ public LoggerContext configure(Props props) {
LoggerContext ctx = helper.getRootContext();
ctx.reset();
- ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(ctx, "CONSOLE", LOG_FORMAT);
- Logger rootLogger = helper.configureLogger(Logger.ROOT_LOGGER_NAME, Level.INFO);
- rootLogger.addAppender(consoleAppender);
+ helper.configureRootLogger(ctx, props, "", "es");
+
return ctx;
}
}
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
index d8bf14841fc..7163399b86a 100644
--- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
+++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
@@ -86,7 +86,7 @@ public class SearchServer implements Monitored {
public static void main(String... args) {
ProcessEntryPoint entryPoint = ProcessEntryPoint.createForArguments(args);
- new SearchLogging().configure();
+ new SearchLogging().configure(entryPoint.getProps());
SearchServer searchServer = new SearchServer(entryPoint.getProps());
entryPoint.launch(searchServer);
}
diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java
index 87944620241..dde89d32d45 100644
--- a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java
+++ b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java
@@ -21,17 +21,38 @@ package org.sonar.search;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
+import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.ConsoleAppender;
+import ch.qos.logback.core.FileAppender;
+import java.io.File;
+import java.io.IOException;
+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 org.sonar.process.LogbackHelper;
+import org.sonar.process.ProcessProperties;
+import org.sonar.process.Props;
import static org.assertj.core.api.Assertions.assertThat;
public class SearchLoggingTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
- SearchLogging underTest = new SearchLogging();
+ private File logDir;
+
+ private Props props = new Props(new Properties());
+ private SearchLogging underTest = new SearchLogging();
+
+ @Before
+ public void setUp() throws IOException {
+ logDir = temp.newFolder();
+ props.set(ProcessProperties.PATH_LOGS, logDir.getAbsolutePath());
+ }
@AfterClass
public static void resetLogback() throws Exception {
@@ -39,11 +60,25 @@ public class SearchLoggingTest {
}
@Test
- public void log_to_console() {
- LoggerContext ctx = underTest.configure();
+ public void do_not_log_to_console() {
+ LoggerContext ctx = underTest.configure(props);
Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
Appender appender = root.getAppender("CONSOLE");
- assertThat(appender).isInstanceOf(ConsoleAppender.class);
+ assertThat(appender).isNull();
+ }
+
+ @Test
+ public void log_to_es_file() {
+ LoggerContext ctx = underTest.configure(props);
+
+ Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
+ Appender<ILoggingEvent> appender = root.getAppender("file");
+ assertThat(appender).isInstanceOf(FileAppender.class);
+ FileAppender fileAppender = (FileAppender) appender;
+ assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.log").getAbsolutePath());
+ assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
+ PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
+ assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level [][%logger{20}] %msg%n");
}
}