]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8335 move RootLoggerConfig out of LogbackHelper
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 28 Nov 2016 15:55:57 +0000 (16:55 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 1 Dec 2016 11:29:39 +0000 (12:29 +0100)
server/sonar-process/src/main/java/org/sonar/process/logging/LogbackHelper.java
server/sonar-process/src/main/java/org/sonar/process/logging/RootLoggerConfig.java [new file with mode: 0644]
server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java
server/sonar-server/src/main/java/org/sonar/server/app/ServerProcessLogging.java
sonar-application/src/main/java/org/sonar/application/AppLogging.java

index 15b129cdbe09e8eb6460d13a6b28b6cbeabb6442..6d7589a618a0da063c8eb01349ae8104c39fcb80 100644 (file)
@@ -49,7 +49,6 @@ import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
 import static java.lang.String.format;
-import static java.util.Objects.requireNonNull;
 import static org.slf4j.Logger.ROOT_LOGGER_NAME;
 
 /**
@@ -97,53 +96,7 @@ public class LogbackHelper {
     return propagator;
   }
 
-  public static final class RootLoggerConfig {
-    private final ProcessId processId;
-    private final String threadIdFieldPattern;
-
-    private RootLoggerConfig(Builder builder) {
-      this.processId = requireNonNull(builder.processId);
-      this.threadIdFieldPattern = builder.threadIdFieldPattern;
-    }
-
-    public static Builder newRootLoggerConfigBuilder() {
-      return new Builder();
-    }
-
-    ProcessId getProcessId() {
-      return processId;
-    }
-
-    String getThreadIdFieldPattern() {
-      return threadIdFieldPattern;
-    }
-
-    public static final class Builder {
-      @CheckForNull
-      private ProcessId processId;
-      private String threadIdFieldPattern = "";
-
-      private Builder() {
-        // prevents instantiation outside RootLoggerConfig, use static factory method
-      }
-
-      public Builder setProcessId(ProcessId processId) {
-        this.processId = processId;
-        return this;
-      }
-
-      public Builder setThreadIdFieldPattern(String threadIdFieldPattern) {
-        this.threadIdFieldPattern = requireNonNull(threadIdFieldPattern, "threadIdFieldPattern can't be null");
-        return this;
-      }
-
-      public RootLoggerConfig build() {
-        return new RootLoggerConfig(this);
-      }
-    }
-  }
-
-  public String buildLogPattern(LogbackHelper.RootLoggerConfig config) {
+  public String buildLogPattern(RootLoggerConfig config) {
     return LOG_FORMAT
       .replace(PROCESS_NAME_PLACEHOLDER, config.getProcessId().getKey())
       .replace(THREAD_ID_PLACEHOLDER, config.getThreadIdFieldPattern());
@@ -189,7 +142,7 @@ public class LogbackHelper {
     return fileAppender;
   }
 
-  public FileAppender<ILoggingEvent> newFileAppender(LoggerContext ctx, Props props, LogbackHelper.RootLoggerConfig config, String logPattern) {
+  public FileAppender<ILoggingEvent> newFileAppender(LoggerContext ctx, Props props, RootLoggerConfig config, String logPattern) {
     RollingPolicy rollingPolicy = createRollingPolicy(ctx, props, config.getProcessId().getLogFilenamePrefix());
     FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file_" + config.getProcessId().getLogFilenamePrefix());
     fileAppender.setContext(ctx);
diff --git a/server/sonar-process/src/main/java/org/sonar/process/logging/RootLoggerConfig.java b/server/sonar-process/src/main/java/org/sonar/process/logging/RootLoggerConfig.java
new file mode 100644 (file)
index 0000000..d1773e8
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.process.logging;
+
+import javax.annotation.CheckForNull;
+import org.sonar.process.ProcessId;
+
+import static java.util.Objects.requireNonNull;
+
+public final class RootLoggerConfig {
+  private final ProcessId processId;
+  private final String threadIdFieldPattern;
+
+  private RootLoggerConfig(Builder builder) {
+    this.processId = requireNonNull(builder.processId);
+    this.threadIdFieldPattern = builder.threadIdFieldPattern;
+  }
+
+  public static Builder newRootLoggerConfigBuilder() {
+    return new Builder();
+  }
+
+  ProcessId getProcessId() {
+    return processId;
+  }
+
+  String getThreadIdFieldPattern() {
+    return threadIdFieldPattern;
+  }
+
+  public static final class Builder {
+    @CheckForNull
+    private ProcessId processId;
+    private String threadIdFieldPattern = "";
+
+    private Builder() {
+      // prevents instantiation outside RootLoggerConfig, use static factory method
+    }
+
+    public Builder setProcessId(ProcessId processId) {
+      this.processId = processId;
+      return this;
+    }
+
+    public Builder setThreadIdFieldPattern(String threadIdFieldPattern) {
+      this.threadIdFieldPattern = requireNonNull(threadIdFieldPattern, "threadIdFieldPattern can't be null");
+      return this;
+    }
+
+    public RootLoggerConfig build() {
+      return new RootLoggerConfig(this);
+    }
+  }
+}
index 5d3e857bedecc66cfc13526e67dec51bebdca856..38e26b7621af4c2fb19c6b6942752b0545f990a8 100644 (file)
@@ -23,8 +23,9 @@ import ch.qos.logback.classic.LoggerContext;
 import org.sonar.process.logging.LogbackHelper;
 import org.sonar.process.ProcessId;
 import org.sonar.process.Props;
+import org.sonar.process.logging.RootLoggerConfig;
 
-import static org.sonar.process.logging.LogbackHelper.RootLoggerConfig.newRootLoggerConfigBuilder;
+import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder;
 
 public class SearchLogging {
 
@@ -34,7 +35,7 @@ public class SearchLogging {
     LoggerContext ctx = helper.getRootContext();
     ctx.reset();
 
-    LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build();
+    RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build();
 
     String logPattern = helper.buildLogPattern(config);
     helper.configureGlobalFileLog(props, config, logPattern);
index 4692e71401c13f21f6899bc38fa5180d35e4c3ae..daadb4f1ddff419ae3abcb8dfec17b8ebe1034de 100644 (file)
@@ -25,9 +25,10 @@ import java.util.Set;
 import org.sonar.process.logging.LogbackHelper;
 import org.sonar.process.ProcessId;
 import org.sonar.process.Props;
+import org.sonar.process.logging.RootLoggerConfig;
 import org.sonar.server.platform.ServerLogging;
 
-import static org.sonar.process.logging.LogbackHelper.RootLoggerConfig.newRootLoggerConfigBuilder;
+import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder;
 
 public abstract class ServerProcessLogging {
   protected static final Set<String> JMX_RMI_LOGGER_NAMES = ImmutableSet.of(
@@ -64,7 +65,7 @@ public abstract class ServerProcessLogging {
   protected abstract void extendConfiguration(LogbackHelper helper, Props props);
 
   private void configureRootLogger(Props props) {
-    LogbackHelper.RootLoggerConfig config = newRootLoggerConfigBuilder()
+    RootLoggerConfig config = newRootLoggerConfigBuilder()
       .setProcessId(processId)
       .setThreadIdFieldPattern(threadIdFieldPattern)
       .build();
index 992cca0ec65f18b0f4060c080048aebc77de8d0b..84d0b074b0ff3781e85c7fa62b969ea8323385ca 100644 (file)
@@ -27,9 +27,10 @@ import ch.qos.logback.core.FileAppender;
 import org.sonar.process.logging.LogbackHelper;
 import org.sonar.process.ProcessId;
 import org.sonar.process.Props;
+import org.sonar.process.logging.RootLoggerConfig;
 
 import static org.slf4j.Logger.ROOT_LOGGER_NAME;
-import static org.sonar.process.logging.LogbackHelper.RootLoggerConfig.newRootLoggerConfigBuilder;
+import static org.sonar.process.logging.RootLoggerConfig.newRootLoggerConfigBuilder;
 import static org.sonar.process.monitor.StreamGobbler.LOGGER_GOBBLER;
 
 /**
@@ -108,7 +109,7 @@ class AppLogging {
   private static final String CONSOLE_PLAIN_APPENDER = "CONSOLE";
   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()
+  private static final RootLoggerConfig APP_ROOT_LOGGER_CONFIG = newRootLoggerConfigBuilder()
     .setProcessId(ProcessId.APP)
     .build();