]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5621 Merge server log files into a single one
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 24 Sep 2014 16:19:50 +0000 (18:19 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 24 Sep 2014 16:19:50 +0000 (18:19 +0200)
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/JavaProcessLauncher.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/TerminatorThread.java
server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-search/src/main/resources/org/sonar/search/logback.xml
server/sonar-server/src/main/java/org/sonar/server/app/Logging.java
server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml
sonar-application/src/main/resources/org/sonar/application/logback.xml
sonar-core/src/main/java/org/sonar/core/config/Logback.java

index 77a4b607d0d5bdd3aafcd2a202e0cd75b10b0c69..3cedc1c9c84cab1c14a0aee165bb6f1147ecea76 100644 (file)
@@ -49,7 +49,7 @@ public class JavaProcessLauncher {
       commands.prepare();
 
       ProcessBuilder processBuilder = create(command);
-      LoggerFactory.getLogger(getClass()).info("Launch {}: {}",
+      LoggerFactory.getLogger(getClass()).info("Launch process[{}]: {}",
         command.getKey(), StringUtils.join(processBuilder.command(), " "));
       process = processBuilder.start();
       StreamGobbler inputGobbler = new StreamGobbler(process.getInputStream(), command.getKey());
index 672fdf6cb6ccf57aa0851df37f920efd84a739dd..31eae8e9ba3deaf7d67a3cf9a3d754acff130cba 100644 (file)
@@ -90,7 +90,6 @@ class ProcessRef {
         ProcessUtils.sendKillSignal(process);
         // signal is sent, waiting for shutdown hooks to be executed (or not... it depends on OS)
         process.waitFor();
-        LoggerFactory.getLogger(getClass()).info(String.format("%s is stopped", this));
 
       } catch (InterruptedException ignored) {
         // can't wait for the termination of process. Let's assume it's down.
index d5f54e3324860dd3d5fbdc2c26088327689e338d..2115884b189f9ce7a206c80370819a0949626953 100644 (file)
@@ -38,7 +38,7 @@ class StreamGobbler extends Thread {
   private final Logger logger;
 
   StreamGobbler(InputStream is, String processKey) {
-    this(is, processKey, LoggerFactory.getLogger(processKey));
+    this(is, processKey, LoggerFactory.getLogger("gobbler"));
   }
 
   StreamGobbler(InputStream is, String processKey, Logger logger) {
index b40291f164a36fdbb9f289b9770368d0b8367126..a774868f75a2671a276ecf6b91032cdc3767a7fc 100644 (file)
@@ -68,6 +68,7 @@ class TerminatorThread extends Thread {
           LoggerFactory.getLogger(getClass()).info(String.format("%s failed to stop in a timely fashion. Killing it.", ref));
         }
         ref.stop();
+        LoggerFactory.getLogger(getClass()).info(String.format("%s is stopped", ref));
       }
     }
   }
index 18893090bf37805c84e071b24b1231ea5ffc762c..2fb7baa865e119a5dd4cad02ae340e3508f23aad 100644 (file)
@@ -50,8 +50,8 @@ public class ProcessLogging {
     Logger consoleLogger = (Logger) LoggerFactory.getLogger("console");
     Appender<ILoggingEvent> consoleAppender = consoleLogger.getAppender("CONSOLE");
 
-    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-    rootLogger.addAppender(consoleAppender);
+    Logger gobblerLogger = (Logger) LoggerFactory.getLogger("gobbler");
+    gobblerLogger.addAppender(consoleAppender);
   }
 
   /**
index cb039b55162c7c4136026fd7ce30e97ba2cdd9e3..d63abe3b2b50fd92fa54a71ca1db7fabda42390d 100644 (file)
@@ -249,7 +249,7 @@ public class SearchServer implements Monitored {
 
   @Override
   public synchronized void stop() {
-    if (!node.isClosed()) {
+    if (node != null && !node.isClosed()) {
       node.close();
     }
   }
index d10553b643bc32e570840a946c9aa9f38ac5e5c8..3c24d95cdc0c1640b94fb7536e21b9e070bf2063 100644 (file)
@@ -12,7 +12,7 @@
   <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <pattern>
-        %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %X %msg%n
+        %d{yyyy.MM.dd HH:mm:ss} %-5level sea[%logger{20}] %X %msg%n
       </pattern>
     </encoder>
   </appender>
index fefc1444a3b9f12e39962522e52a4f1027ed328e..e5d8c52b225aa1f6c44ee235b47a5a8e7abf416a 100644 (file)
@@ -37,20 +37,15 @@ import java.util.logging.LogManager;
 
 class Logging {
 
-  private static final String CONFIG_LOG_CONSOLE = "sonar.log.console";
-
   private static final String LOG_COMMON_PREFIX = "%d{yyyy.MM.dd HH:mm:ss} %-5level ";
   private static final String LOG_COMMON_SUFFIX = "%msg%n";
 
-  private static final String LOG_LOGFILE_SPECIFIC_PART = "[%logger{20}] %X ";
+  private static final String LOG_LOGFILE_SPECIFIC_PART = "web[%logger{20}] %X ";
   private static final String LOG_FULL_SPECIFIC_PART = "%thread ";
 
   private static final String LOGFILE_STANDARD_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_LOGFILE_SPECIFIC_PART + LOG_COMMON_SUFFIX;
   private static final String LOGFILE_FULL_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_FULL_SPECIFIC_PART + LOG_LOGFILE_SPECIFIC_PART + LOG_COMMON_SUFFIX;
 
-  private static final String CONSOLE_STANDARD_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_COMMON_SUFFIX;
-  private static final String CONSOLE_FULL_LOGGING_FORMAT = LOG_COMMON_PREFIX + LOG_FULL_SPECIFIC_PART + LOG_COMMON_SUFFIX;
-
   static final String ACCESS_RELATIVE_PATH = "WEB-INF/config/logback-access.xml";
   static final String PROPERTY_ENABLE_ACCESS_LOGS = "sonar.web.accessLogs.enable";
 
@@ -71,12 +66,9 @@ class Logging {
   private static void configureLogback(Props props) {
     String configProfilingLevel = props.value(Profiling.CONFIG_PROFILING_LEVEL, "NONE");
     Profiling.Level profilingLevel = Profiling.Level.fromConfigString(configProfilingLevel);
-    String consoleEnabled = props.value(CONFIG_LOG_CONSOLE, "false");
     Map<String, String> variables = ImmutableMap.of(
       "sonar.path.logs", props.nonNullValue("sonar.path.logs"),
-      "LOGFILE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT,
-      "CONSOLE_LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? CONSOLE_FULL_LOGGING_FORMAT : CONSOLE_STANDARD_LOGGING_FORMAT,
-      "CONSOLE_ENABLED", consoleEnabled);
+      "LOGGING_FORMAT", profilingLevel == Profiling.Level.FULL ? LOGFILE_FULL_LOGGING_FORMAT : LOGFILE_STANDARD_LOGGING_FORMAT);
     Logback.configure("/org/sonar/server/platform/logback.xml", variables);
   }
 
index 84ce76baece8d93a226dd9d7b39c90717d70884b..9dc53c89a8b618a4bba2c7d02bd48e98f77f7b34 100644 (file)
@@ -12,7 +12,7 @@
   <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <pattern>
-        ${LOGFILE_LOGGING_FORMAT}
+        ${LOGGING_FORMAT}
       </pattern>
     </encoder>
   </appender>
index e34156819f0a65b718c8338702cfec0a3145599d..cbcd991ded9f2cb018886d8271bbf49b490b34ff 100644 (file)
       <param name="MaxFileSize" value="10MB"/>
     </triggeringPolicy>
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-      <pattern>%3.3logger %msg%n</pattern>
+      <pattern>%msg%n</pattern>
+    </encoder>
+  </appender>
+
+  <appender name="APP" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+      <pattern>%d{yyyy.MM.dd HH:mm:ss} %-5level app[%logger{20}] %msg%n</pattern>
     </encoder>
   </appender>
 
   <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <pattern>
-        app %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %msg%n
+        %msg%n
       </pattern>
     </encoder>
   </appender>
 
-  <logger name="console">
+  <logger name="console" additivity="false">
     <appender-ref ref="CONSOLE"/>
   </logger>
 
+  <logger name="gobbler" additivity="false">
+    <appender-ref ref="LOGFILE"/>
+  </logger>
+
   <root>
     <level value="INFO"/>
-    <appender-ref ref="LOGFILE"/>
+    <appender-ref ref="APP"/>
   </root>
 
 </configuration>
index 9d2eb8332bb482a4cc49e9c4e926003b8106343e..ac9a7b4e00c3b01f4b193319969a3c8f8397cf31 100644 (file)
 package org.sonar.core.config;
 
 import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
 import ch.qos.logback.classic.joran.JoranConfigurator;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.ConsoleAppender;
 import ch.qos.logback.core.joran.spi.JoranException;
 import ch.qos.logback.core.util.StatusPrinter;
 import org.apache.commons.io.FileUtils;
@@ -74,11 +69,6 @@ public class Logback implements BatchComponent, ServerComponent {
       JoranConfigurator configurator = new JoranConfigurator();
       configurator.setContext(configureContext(lc, substitutionVariables));
       configurator.doConfigure(input);
-      if (isConsoleEnabled(substitutionVariables)) {
-        Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
-        rootLogger.setAdditive(false);
-        rootLogger.addAppender(consoleAppender(lc, substitutionVariables));
-      }
     } catch (JoranException e) {
       // StatusPrinter will handle this
     } finally {
@@ -95,22 +85,6 @@ public class Logback implements BatchComponent, ServerComponent {
     return context;
   }
 
-  private static Boolean isConsoleEnabled(Map<String, String> substitutionVariables) {
-    return Boolean.valueOf(substitutionVariables.get("CONSOLE_ENABLED"));
-  }
-
-  private static Appender<ILoggingEvent> consoleAppender(LoggerContext context, Map<String, String> substitutionVariables) {
-    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
-    encoder.setPattern(substitutionVariables.get("CONSOLE_LOGGING_FORMAT"));
-    encoder.setContext(context);
-    encoder.start();
-    ConsoleAppender<ILoggingEvent> console = new ConsoleAppender<ILoggingEvent>();
-    console.setEncoder(encoder);
-    console.setContext(context);
-    console.start();
-    return console;
-  }
-
   public void setLoggerLevel(String loggerName, Level level) {
     ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(loggerName)).setLevel(level);
   }