aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-16 15:16:56 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2016-11-17 00:14:11 +0100
commit75bae1e0539dd6504c898814621262f1739d08d4 (patch)
tree73c52435f77aa57ee9af73313af8f73ecba3d191
parent5d9f45a6a15023c695ddb3622be5e44b8d31c10e (diff)
downloadsonarqube-75bae1e0539dd6504c898814621262f1739d08d4.tar.gz
sonarqube-75bae1e0539dd6504c898814621262f1739d08d4.zip
SONAR-8383 expose association process -> log filename
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java51
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessId.java18
-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/server/app/ServerProcessLogging.java3
-rw-r--r--sonar-application/src/main/java/org/sonar/application/AppLogging.java3
5 files changed, 31 insertions, 47 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 024c2835330..cd7ae2dae59 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
@@ -94,46 +94,37 @@ public class LogbackHelper {
}
public static final class RootLoggerConfig {
- private final String processName;
+ private final ProcessId processId;
private final String threadIdFieldPattern;
- private final String fileNamePrefix;
private RootLoggerConfig(Builder builder) {
- this.processName = builder.processName;
+ this.processId = requireNonNull(builder.processId);
this.threadIdFieldPattern = builder.threadIdFieldPattern;
- this.fileNamePrefix = builder.fileNamePrefix;
}
public static Builder newRootLoggerConfigBuilder() {
return new Builder();
}
- public String getProcessName() {
- return processName;
+ public ProcessId getProcessId() {
+ return processId;
}
String getThreadIdFieldPattern() {
return threadIdFieldPattern;
}
- String getFileNamePrefix() {
- return fileNamePrefix;
- }
-
public static final class Builder {
@CheckForNull
- private String processName;
+ public ProcessId processId;
private String threadIdFieldPattern = "";
- @CheckForNull
- private String fileNamePrefix;
private Builder() {
// prevents instantiation outside RootLoggerConfig, use static factory method
}
- public Builder setProcessName(String processName) {
- checkProcessName(processName);
- this.processName = processName;
+ public Builder setProcessId(ProcessId processId) {
+ this.processId = processId;
return this;
}
@@ -142,27 +133,7 @@ public class LogbackHelper {
return this;
}
- public Builder setFileNamePrefix(String fileNamePrefix) {
- checkFileName(fileNamePrefix);
- this.fileNamePrefix = fileNamePrefix;
- return this;
- }
-
- private static void checkFileName(String fileName) {
- if (requireNonNull(fileName, "fileNamePrefix can't be null").isEmpty()) {
- throw new IllegalArgumentException("fileNamePrefix can't be empty");
- }
- }
-
- private static void checkProcessName(String fileName) {
- if (requireNonNull(fileName, "processName can't be null").isEmpty()) {
- throw new IllegalArgumentException("processName can't be empty");
- }
- }
-
public RootLoggerConfig build() {
- checkProcessName(this.processName);
- checkFileName(this.fileNamePrefix);
return new RootLoggerConfig(this);
}
}
@@ -170,7 +141,7 @@ public class LogbackHelper {
public String buildLogPattern(LogbackHelper.RootLoggerConfig config) {
return LOG_FORMAT
- .replace(PROCESS_NAME_PLACEHOLDER, config.getProcessName())
+ .replace(PROCESS_NAME_PLACEHOLDER, config.getProcessId().getKey())
.replace(THREAD_ID_PLACEHOLDER, config.getThreadIdFieldPattern());
}
@@ -197,7 +168,7 @@ 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's name will use the prefix defined in {@link RootLoggerConfig#getProcessId()#getLogFilenamePrefix()}.</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>
@@ -215,8 +186,8 @@ public class LogbackHelper {
}
public FileAppender<ILoggingEvent> newFileAppender(LoggerContext ctx, Props props, LogbackHelper.RootLoggerConfig config, String logPattern) {
- RollingPolicy rollingPolicy = createRollingPolicy(ctx, props, config.getFileNamePrefix());
- FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file_" + config.getFileNamePrefix());
+ RollingPolicy rollingPolicy = createRollingPolicy(ctx, props, config.getProcessId().getLogFilenamePrefix());
+ FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file_" + config.getProcessId().getLogFilenamePrefix());
fileAppender.setContext(ctx);
PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
fileEncoder.setContext(ctx);
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
index 9189ada6cd2..37db2a08f32 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessId.java
@@ -21,14 +21,20 @@ package org.sonar.process;
public enum ProcessId {
- APP("app", 0), ELASTICSEARCH("es", 1), WEB_SERVER("web", 2), COMPUTE_ENGINE("ce", 3);
+ APP("app", 0, "sonar"),
+ ELASTICSEARCH("es", 1, "es"),
+ WEB_SERVER("web", 2, "web"),
+ COMPUTE_ENGINE("ce", 3, "ce");
private final String key;
private final int ipcIndex;
+ private final String logFilenamePrefix;
- ProcessId(String key, int ipcIndex) {
+
+ ProcessId(String key, int ipcIndex, String logFilenamePrefix) {
this.key = key;
this.ipcIndex = ipcIndex;
+ this.logFilenamePrefix = logFilenamePrefix;
}
public String getKey() {
@@ -42,11 +48,19 @@ public enum ProcessId {
return ipcIndex;
}
+ /**
+ * Prefix of log file, for example "web" for file "web.log"
+ */
+ public String getLogFilenamePrefix() {
+ return logFilenamePrefix;
+ }
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[");
sb.append("key='").append(key).append('\'');
sb.append(", ipcIndex=").append(ipcIndex);
+ sb.append(", logFilenamePrefix=").append(logFilenamePrefix);
sb.append(']');
return sb.toString();
}
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 a7167c9b33e..04136ab0698 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
@@ -21,6 +21,7 @@ package org.sonar.search;
import ch.qos.logback.classic.LoggerContext;
import org.sonar.process.LogbackHelper;
+import org.sonar.process.ProcessId;
import org.sonar.process.Props;
import static org.sonar.process.LogbackHelper.RootLoggerConfig.newRootLoggerConfigBuilder;
@@ -33,7 +34,7 @@ public class SearchLogging {
LoggerContext ctx = helper.getRootContext();
ctx.reset();
- LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessName("es").setFileNamePrefix("es").build();
+ LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build();
String logPattern = helper.buildLogPattern(config);
helper.configureGlobalFileLog(props, config, logPattern);
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 0936cd501f0..c8c0d9bc6b4 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
@@ -65,9 +65,8 @@ public abstract class ServerProcessLogging {
private void configureRootLogger(Props props) {
LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder()
- .setProcessName(processId.getKey())
+ .setProcessId(processId)
.setThreadIdFieldPattern(threadIdFieldPattern)
- .setFileNamePrefix(processId.getKey())
.build();
String logPattern = helper.buildLogPattern(config);
diff --git a/sonar-application/src/main/java/org/sonar/application/AppLogging.java b/sonar-application/src/main/java/org/sonar/application/AppLogging.java
index 6a5586b9381..69ba954e4f1 100644
--- a/sonar-application/src/main/java/org/sonar/application/AppLogging.java
+++ b/sonar-application/src/main/java/org/sonar/application/AppLogging.java
@@ -109,8 +109,7 @@ class AppLogging {
private static final String APP_CONSOLE_APPENDER = "APP_CONSOLE";
private static final String GOBBLER_PLAIN_CONSOLE = "GOBBLER_CONSOLE";
private static final LogbackHelper.RootLoggerConfig APP_ROOT_LOGGER_CONFIG = newRootLoggerConfigBuilder()
- .setProcessName("app")
- .setFileNamePrefix("sonar")
+ .setProcessId(ProcessId.APP)
.build();
private final LogbackHelper helper = new LogbackHelper();