aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server
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-server
parent38242dc18f85afbf8a134ffbe48be5cf8e98eceb (diff)
downloadsonarqube-adf8fbe5364084c3da6d004d1ad55cba0620be4d.tar.gz
sonarqube-adf8fbe5364084c3da6d004d1ad55cba0620be4d.zip
SONAR-8333 make ES log into its own log file
Diffstat (limited to 'server/sonar-server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java36
-rw-r--r--server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java2
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java2
3 files changed, 6 insertions, 34 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java b/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java
index 2d9976b0b64..50feea704f6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java
@@ -19,11 +19,7 @@
*/
package org.sonar.server.app;
-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.FileAppender;
import java.util.logging.LogManager;
import org.slf4j.bridge.SLF4JBridgeHandler;
import org.sonar.api.utils.MessageException;
@@ -34,16 +30,13 @@ import org.sonar.server.platform.ServerLogging;
public abstract class ServerProcessLogging {
private static final String LOG_LEVEL_PROPERTY = "sonar.log.level";
- private static final String PROCESS_NAME_PLACEHOLDER = "XXXX";
- private static final String THREAD_ID_PLACEHOLDER = "ZZZZ";
- private static final String LOG_FORMAT = "%d{yyyy.MM.dd HH:mm:ss} %-5level " + PROCESS_NAME_PLACEHOLDER + "[" + THREAD_ID_PLACEHOLDER + "][%logger{20}] %msg%n";
private final String processName;
- private final String threadIdPattern;
+ private final String threadIdFieldPattern;
private final LogbackHelper helper = new LogbackHelper();
- protected ServerProcessLogging(String processName, String threadIdPattern) {
+ protected ServerProcessLogging(String processName, String threadIdFieldPattern) {
this.processName = processName;
- this.threadIdPattern = threadIdPattern;
+ this.threadIdFieldPattern = threadIdFieldPattern;
}
public LoggerContext configure(Props props) {
@@ -51,7 +44,7 @@ public abstract class ServerProcessLogging {
ctx.reset();
helper.enableJulChangePropagation(ctx);
- configureRootLogger(ctx, props);
+ helper.configureRootLogger(ctx, props, threadIdFieldPattern, processName);
configureLevels(props);
// Configure java.util.logging, used by Tomcat, in order to forward to slf4j
@@ -60,27 +53,6 @@ public abstract class ServerProcessLogging {
return ctx;
}
- private void configureRootLogger(LoggerContext ctx, Props props) {
- String logFormat = LOG_FORMAT
- .replace(PROCESS_NAME_PLACEHOLDER, processName)
- .replace(THREAD_ID_PLACEHOLDER, threadIdPattern);
- // configure appender
- LogbackHelper.RollingPolicy rollingPolicy = helper.createRollingPolicy(ctx, props, processName);
- FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file");
- fileAppender.setContext(ctx);
- PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
- fileEncoder.setContext(ctx);
- fileEncoder.setPattern(logFormat);
- fileEncoder.start();
- fileAppender.setEncoder(fileEncoder);
- fileAppender.start();
-
- // configure logger
- Logger rootLogger = ctx.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
- rootLogger.addAppender(fileAppender);
- rootLogger.detachAppender("console");
- }
-
private void configureLevels(Props props) {
String levelCode = props.value(LOG_LEVEL_PROPERTY, "INFO");
LoggerLevel level;
diff --git a/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java b/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java
index b2e39b3e5d8..fa94f15e1b1 100644
--- a/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/ce/log/CeProcessLoggingTest.java
@@ -83,7 +83,7 @@ public class CeProcessLoggingTest {
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.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 ce[%X{ceTaskUuid}][%logger{20}] %msg%n");
+ assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level [%X{ceTaskUuid}][%logger{20}] %msg%n");
}
@Test
diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java
index 170ea8b6c11..9c9e60e6d34 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java
@@ -83,7 +83,7 @@ public class WebServerProcessLoggingTest {
assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "web.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 web[%X{UID}][%logger{20}] %msg%n");
+ assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level [%X{UID}][%logger{20}] %msg%n");
}
@Test