aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-11-15 11:17:33 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-11-16 18:27:52 +0100
commit0518e8253c82e39e2d7c7d8aa82873edc32d442d (patch)
treea0ef4983f3ca89aeb44d26d0868bc5c34777352b /server
parent640a441d745476008b20006140c4d3b0e88d06b0 (diff)
downloadsonarqube-0518e8253c82e39e2d7c7d8aa82873edc32d442d.tar.gz
sonarqube-0518e8253c82e39e2d7c7d8aa82873edc32d442d.zip
SONAR-8335 support properties to configure log level per JVM
Diffstat (limited to 'server')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java40
-rw-r--r--server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/ce/log/CeProcessLogging.java5
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java13
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/app/WebServerProcessLogging.java3
5 files changed, 40 insertions, 24 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 a669c91a9ce..7a86fe5dd4a 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
@@ -53,11 +53,12 @@ import static org.slf4j.Logger.ROOT_LOGGER_NAME;
public class LogbackHelper {
private static final String ALL_LOGS_TO_CONSOLE_PROPERTY = "sonar.log.console";
+ private static final String PROCESS_NAME_PLACEHOLDER = "XXXX";
+ private static final String THREAD_ID_PLACEHOLDER = "ZZZZ";
private static final String SONAR_LOG_LEVEL_PROPERTY = "sonar.log.level";
+ private static final String SONAR_PROCESS_LOG_LEVEL_PROPERTY = "sonar.log.level." + PROCESS_NAME_PLACEHOLDER;
private static final String ROLLING_POLICY_PROPERTY = "sonar.log.rollingPolicy";
private static final String MAX_FILES_PROPERTY = "sonar.log.maxFiles";
- 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";
public static final Set<Level> ALLOWED_ROOT_LOG_LEVELS = unmodifiableSet(setOf(Level.TRACE, Level.DEBUG, Level.INFO));
@@ -164,8 +165,8 @@ public class LogbackHelper {
public String buildLogPattern(LogbackHelper.RootLoggerConfig config) {
return LOG_FORMAT
- .replace(PROCESS_NAME_PLACEHOLDER, config.getProcessName())
- .replace(THREAD_ID_PLACEHOLDER, config.getThreadIdFieldPattern());
+ .replace(PROCESS_NAME_PLACEHOLDER, config.getProcessName())
+ .replace(THREAD_ID_PLACEHOLDER, config.getThreadIdFieldPattern());
}
/**
@@ -190,12 +191,12 @@ public class LogbackHelper {
/**
* Make logback configuration for a process to push all its logs to a log file.
* <p>
- * <ul>
- * <li>the file's name will use the prefix defined in {@link RootLoggerConfig#getFileNamePrefix()}.</li>
- * <li>the file will follow the rotation policy defined in property {@link #ROLLING_POLICY_PROPERTY} and
- * the max number of files defined in property {@link #MAX_FILES_PROPERTY}</li>
- * <li>the logs will follow the specified log pattern</li>
- * </ul>
+ * <ul>
+ * <li>the file's name will use the prefix defined in {@link RootLoggerConfig#getFileNamePrefix()}.</li>
+ * <li>the file will follow the rotation policy defined in property {@link #ROLLING_POLICY_PROPERTY} and
+ * the max number of files defined in property {@link #MAX_FILES_PROPERTY}</li>
+ * <li>the logs will follow the specified log pattern</li>
+ * </ul>
* </p>
*
* @see #buildLogPattern(RootLoggerConfig)
@@ -254,17 +255,26 @@ public class LogbackHelper {
*
* @throws IllegalArgumentException if the value of {@link #SONAR_LOG_LEVEL_PROPERTY} is not one of {@link #ALLOWED_ROOT_LOG_LEVELS}
*/
- public Level configureRootLogLevel(Props props) {
- return configureRootLogLevel(props, SONAR_LOG_LEVEL_PROPERTY);
+ public Level configureRootLogLevel(Props props, ProcessId processId) {
+ return configureRootLogLevel(props,
+ SONAR_LOG_LEVEL_PROPERTY,
+ SONAR_PROCESS_LOG_LEVEL_PROPERTY.replace(PROCESS_NAME_PLACEHOLDER, processId.getKey()));
}
/**
- * Configure the log level of the root logger reading the value of specified property.
+ * Configure the log level of the root logger reading the value of specified properties. The lowest level will be
+ * applied.
*
* @throws IllegalArgumentException if the value of the specified property is not one of {@link #ALLOWED_ROOT_LOG_LEVELS}
*/
- public Level configureRootLogLevel(Props props, String propertyKey) {
- Level newLevel = Level.toLevel(props.value(propertyKey, Level.INFO.toString()), Level.INFO);
+ public Level configureRootLogLevel(Props props, String... propertyKeys) {
+ Level newLevel = Level.INFO;
+ for (String propertyKey : propertyKeys) {
+ Level level = Level.toLevel(props.value(propertyKey, Level.INFO.toString()), Level.INFO);
+ if (!level.isGreaterOrEqual(newLevel)) {
+ newLevel = level;
+ }
+ }
return configureRootLogLevel(newLevel);
}
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 62c710e929a..5a35bd69c65 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
@@ -38,7 +38,8 @@ public class SearchLogging {
String logPattern = helper.buildLogPattern(config);
helper.configureGlobalFileLog(props, config, logPattern);
helper.configureForSubprocessGobbler(props, logPattern);
- helper.configureRootLogLevel(props);
+ // SQ's global log level must not change ES's log level
+ helper.configureRootLogLevel(props, "sonar.log.es.level");
return ctx;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/ce/log/CeProcessLogging.java b/server/sonar-server/src/main/java/org/sonar/ce/log/CeProcessLogging.java
index 201878865df..e756cd1c251 100644
--- a/server/sonar-server/src/main/java/org/sonar/ce/log/CeProcessLogging.java
+++ b/server/sonar-server/src/main/java/org/sonar/ce/log/CeProcessLogging.java
@@ -19,16 +19,19 @@
*/
package org.sonar.ce.log;
+import org.sonar.process.ProcessId;
import org.sonar.process.Props;
import org.sonar.server.app.ServerProcessLogging;
+import static org.sonar.ce.log.CeLogging.MDC_CE_TASK_UUID;
+
/**
* Configure logback for the Compute Engine process. Logs are written to file "ce.log" in SQ's log directory.
*/
public class CeProcessLogging extends ServerProcessLogging {
public CeProcessLogging() {
- super("ce", "%X{ceTaskUuid}");
+ super(ProcessId.COMPUTE_ENGINE, "%X{" + MDC_CE_TASK_UUID + "}");
}
@Override
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 ec9f4e565d4..933f6800314 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
@@ -21,18 +21,19 @@ package org.sonar.server.app;
import ch.qos.logback.classic.LoggerContext;
import org.sonar.process.LogbackHelper;
+import org.sonar.process.ProcessId;
import org.sonar.process.Props;
import org.sonar.server.platform.ServerLogging;
import static org.sonar.process.LogbackHelper.RootLoggerConfig.newRootLoggerConfigBuilder;
public abstract class ServerProcessLogging {
- private final String processName;
+ private final ProcessId processId;
private final String threadIdFieldPattern;
private final LogbackHelper helper = new LogbackHelper();
- protected ServerProcessLogging(String processName, String threadIdFieldPattern) {
- this.processName = processName;
+ protected ServerProcessLogging(ProcessId processId, String threadIdFieldPattern) {
+ this.processId = processId;
this.threadIdFieldPattern = threadIdFieldPattern;
}
@@ -52,16 +53,16 @@ public abstract class ServerProcessLogging {
private void configureRootLogger(Props props) {
LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder()
- .setProcessName(processName)
+ .setProcessName(processId.getKey())
.setThreadIdFieldPattern(threadIdFieldPattern)
- .setFileNamePrefix(processName)
+ .setFileNamePrefix(processId.getKey())
.build();
String logPattern = helper.buildLogPattern(config);
helper.configureGlobalFileLog(props, config, logPattern);
helper.configureForSubprocessGobbler(props, logPattern);
- helper.configureRootLogLevel(props);
+ helper.configureRootLogLevel(props, processId);
ServerLogging.configureHardcodedLevels(helper);
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/WebServerProcessLogging.java b/server/sonar-server/src/main/java/org/sonar/server/app/WebServerProcessLogging.java
index f10f249db8d..f4f0753f214 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/app/WebServerProcessLogging.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/app/WebServerProcessLogging.java
@@ -21,6 +21,7 @@ package org.sonar.server.app;
import java.util.logging.LogManager;
import org.slf4j.bridge.SLF4JBridgeHandler;
+import org.sonar.process.ProcessId;
import org.sonar.process.Props;
/**
@@ -29,7 +30,7 @@ import org.sonar.process.Props;
public class WebServerProcessLogging extends ServerProcessLogging {
public WebServerProcessLogging() {
- super("web", "%X{UID}");
+ super(ProcessId.WEB_SERVER, "%X{UID}");
}
@Override