]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6057 fix path of archived logs
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Sun, 15 Feb 2015 22:31:57 +0000 (23:31 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 Feb 2015 11:01:20 +0000 (12:01 +0100)
server/sonar-process/src/main/java/org/sonar/process/LogbackHelper.java
server/sonar-process/src/test/java/org/sonar/process/LogbackHelperTest.java

index 862fc22c7a4f9201ec4f22caf5c68bcb95fbf2ad..f45426f67b799f28b1f2a28afb744d9539db0153 100644 (file)
@@ -161,11 +161,12 @@ public class LogbackHelper {
       RollingFileAppender appender = new RollingFileAppender();
       appender.setContext(context);
       appender.setName(appenderName);
-      appender.setFile(new File(logsDir, filenamePrefix + ".log").getAbsolutePath());
+      String filePath = new File(logsDir, filenamePrefix + ".log").getAbsolutePath();
+      appender.setFile(filePath);
 
       TimeBasedRollingPolicy rollingPolicy = new TimeBasedRollingPolicy();
       rollingPolicy.setContext(context);
-      rollingPolicy.setFileNamePattern(filenamePrefix + ".%d{" + datePattern + "}.log");
+      rollingPolicy.setFileNamePattern(StringUtils.replace(filePath, filenamePrefix + ".log", filenamePrefix + ".%d{" + datePattern + "}.log"));
       rollingPolicy.setMaxHistory(maxFiles);
       rollingPolicy.setParent(appender);
       rollingPolicy.start();
@@ -192,7 +193,8 @@ public class LogbackHelper {
       RollingFileAppender appender = new RollingFileAppender();
       appender.setContext(context);
       appender.setName(appenderName);
-      appender.setFile(new File(logsDir, filenamePrefix + ".log").getAbsolutePath());
+      String filePath = new File(logsDir, filenamePrefix + ".log").getAbsolutePath();
+      appender.setFile(filePath);
 
       SizeBasedTriggeringPolicy trigger = new SizeBasedTriggeringPolicy(size);
       trigger.setContext(context);
@@ -201,7 +203,7 @@ public class LogbackHelper {
 
       FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
       rollingPolicy.setContext(context);
-      rollingPolicy.setFileNamePattern(filenamePrefix + ".%i.log");
+      rollingPolicy.setFileNamePattern(StringUtils.replace(filePath, filenamePrefix + ".log", filenamePrefix + ".%i.log"));
       rollingPolicy.setMaxIndex(1);
       rollingPolicy.setMaxIndex(maxFiles);
       rollingPolicy.setMaxIndex(maxFiles);
index d761a2dca76e9f0784e3795187f1315a8c092021..667a5632ebe66407d5249aac8fe7601b51084845 100644 (file)
@@ -110,7 +110,7 @@ public class LogbackHelperTest {
     RollingFileAppender fileAppender = (RollingFileAppender) appender;
     TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) fileAppender.getTriggeringPolicy();
     assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(7);
-    assertThat(triggeringPolicy.getFileNamePattern()).isEqualTo("sonar.%d{yyyy-MM-dd}.log");
+    assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM-dd}.log");
   }
 
   @Test
@@ -137,7 +137,7 @@ public class LogbackHelperTest {
     RollingFileAppender fileAppender = (RollingFileAppender) appender;
     FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) fileAppender.getRollingPolicy();
     assertThat(rollingPolicy.getMaxIndex()).isEqualTo(20);
-    assertThat(rollingPolicy.getFileNamePattern()).isEqualTo("sonar.%i.log");
+    assertThat(rollingPolicy.getFileNamePattern()).endsWith("sonar.%i.log");
     SizeBasedTriggeringPolicy triggeringPolicy = (SizeBasedTriggeringPolicy) fileAppender.getTriggeringPolicy();
     assertThat(triggeringPolicy.getMaxFileSize()).isEqualTo("1MB");
   }
@@ -155,7 +155,7 @@ public class LogbackHelperTest {
     // max 5 monthly files
     TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) appender.getTriggeringPolicy();
     assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(20);
-    assertThat(triggeringPolicy.getFileNamePattern()).isEqualTo("sonar.%d{yyyy-MM}.log");
+    assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM}.log");
   }
 
   @Test