]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5621 merge log files
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 24 Sep 2014 12:35:43 +0000 (14:35 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 24 Sep 2014 12:36:00 +0000 (14:36 +0200)
server/sonar-process/src/main/java/org/sonar/process/ProcessLogging.java
server/sonar-search/src/main/resources/org/sonar/search/logback.xml
server/sonar-server/src/main/resources/org/sonar/server/platform/logback.xml
sonar-application/src/main/java/org/sonar/application/App.java
sonar-application/src/main/resources/org/sonar/application/logback.xml

index c0909a93fb552736e313eeaa58287a7b181e6bfc..18893090bf37805c84e071b24b1231ea5ffc762c 100644 (file)
  */
 package org.sonar.process;
 
+import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
 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.joran.spi.JoranException;
 import ch.qos.logback.core.util.StatusPrinter;
 import org.slf4j.LoggerFactory;
@@ -43,6 +46,14 @@ public class ProcessLogging {
     StatusPrinter.printInCaseOfErrorsOrWarnings(context);
   }
 
+  public void addConsoleAppender() {
+    Logger consoleLogger = (Logger) LoggerFactory.getLogger("console");
+    Appender<ILoggingEvent> consoleAppender = consoleLogger.getAppender("CONSOLE");
+
+    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+    rootLogger.addAppender(consoleAppender);
+  }
+
   /**
    * Extracted only for unit testing
    */
index 648ece82e289f684f1dc7f386f0d8a4c68fe94c6..d10553b643bc32e570840a946c9aa9f38ac5e5c8 100644 (file)
@@ -9,18 +9,8 @@
 <configuration debug="false">
   <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
 
-  <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <File>${sonar.path.logs}/search.log</File>
-    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <param name="FileNamePattern" value="${sonar.path.logs}/search.%i.log"/>
-      <param name="MinIndex" value="1"/>
-      <param name="MaxIndex" value="3"/>
-    </rollingPolicy>
-    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <param name="MaxFileSize" value="5MB"/>
-    </triggeringPolicy>
+  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-      <!-- Use %d{yyyy.MM.dd HH:mm:ss.SSS} to display milliseconds -->
       <pattern>
         %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %X %msg%n
       </pattern>
@@ -29,7 +19,7 @@
 
   <root>
     <level value="INFO"/>
-    <appender-ref ref="LOGFILE"/>
+    <appender-ref ref="CONSOLE"/>
   </root>
 
 </configuration>
index 4607ddb23bf659f2c6df0d6ecc1f0be37fdda051..84ce76baece8d93a226dd9d7b39c90717d70884b 100644 (file)
@@ -9,40 +9,14 @@
 <configuration debug="false">
   <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
 
-  <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <File>${sonar.path.logs}/sonar.log</File>
-    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <param name="FileNamePattern" value="${sonar.path.logs}/sonar.%i.log"/>
-      <param name="MinIndex" value="1"/>
-      <param name="MaxIndex" value="3"/>
-    </rollingPolicy>
-    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <param name="MaxFileSize" value="5MB"/>
-    </triggeringPolicy>
-    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-      <!-- Use %d{yyyy.MM.dd HH:mm:ss.SSS} to display milliseconds -->
-      <pattern>
-        ${LOGFILE_LOGGING_FORMAT}
-      </pattern>
-    </encoder>
-  </appender>
-
   <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
-    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
-      <level>WARN</level>
-    </filter>
     <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
       <pattern>
-        ${CONSOLE_LOGGING_FORMAT}
+        ${LOGFILE_LOGGING_FORMAT}
       </pattern>
     </encoder>
   </appender>
 
-  <logger name="console" additivity="false">
-    <level value="INFO"/>
-    <appender-ref ref="CONSOLE"/>
-  </logger>
-
   <!-- Display Rails warnings and errors  -->
   <logger name="rails">
     <level value="WARN"/>
@@ -93,7 +67,7 @@
 
   <root>
     <level value="INFO"/>
-    <appender-ref ref="LOGFILE"/>
+    <appender-ref ref="CONSOLE"/>
   </root>
 
 </configuration>
index bba2dd730697210b5817ab2c20cd80960c59fa9e..502cf561394b0926844c2302964b58c5fe602105 100644 (file)
@@ -109,7 +109,11 @@ public class App implements Stoppable {
     CommandLineParser cli = new CommandLineParser();
     Properties rawProperties = cli.parseArguments(args);
     Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
-    new ProcessLogging().configure(props, "/org/sonar/application/logback.xml");
+    ProcessLogging logging = new ProcessLogging();
+    logging.configure(props, "/org/sonar/application/logback.xml");
+    if (props.valueAsBoolean("sonar.log.console", false)) {
+      logging.addConsoleAppender();
+    }
 
     App app = new App();
     app.start(props);
index 246afdf89f398ba077b4e157470eaf2008d37440..e34156819f0a65b718c8338702cfec0a3145599d 100644 (file)
@@ -3,17 +3,36 @@
 <configuration debug="false">
   <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"/>
 
+  <appender name="LOGFILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <File>${sonar.path.logs}/sonar.log</File>
+    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+      <param name="FileNamePattern" value="${sonar.path.logs}/sonar.%i.log"/>
+      <param name="MinIndex" value="1"/>
+      <param name="MaxIndex" value="5"/>
+    </rollingPolicy>
+    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+      <param name="MaxFileSize" value="10MB"/>
+    </triggeringPolicy>
+    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+      <pattern>%3.3logger %msg%n</pattern>
+    </encoder>
+  </appender>
+
   <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 %msg%n
+        app %d{yyyy.MM.dd HH:mm:ss} %-5level [%logger{20}] %msg%n
       </pattern>
     </encoder>
   </appender>
 
+  <logger name="console">
+    <appender-ref ref="CONSOLE"/>
+  </logger>
+
   <root>
     <level value="INFO"/>
-    <appender-ref ref="CONSOLE"/>
+    <appender-ref ref="LOGFILE"/>
   </root>
 
 </configuration>