diff options
author | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-10-13 11:47:41 +0200 |
---|---|---|
committer | ssjenka <ssjenka@ops-slave-fedora25-1.internal.sonarsource.com> | 2017-10-13 11:47:41 +0200 |
commit | 8500b948caa9c604a2f9fbbbb5b70b6189be0373 (patch) | |
tree | 9ea98f2323d0bbef1b69684eb01f492f9499020f /server/sonar-process | |
parent | 544a307e4bbf159efd77bd8937519e75aae9de78 (diff) | |
parent | 06de23dbd2ae73dfffdd71c2e601b3ecb158d166 (diff) | |
download | sonarqube-8500b948caa9c604a2f9fbbbb5b70b6189be0373.tar.gz sonarqube-8500b948caa9c604a2f9fbbbb5b70b6189be0373.zip |
Automatic merge from branch-6.6
* origin/branch-6.6:
SONAR-8798 fix error when sonar.log.maxFiles=0
Diffstat (limited to 'server/sonar-process')
2 files changed, 61 insertions, 8 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/logging/Log4JPropertiesBuilder.java b/server/sonar-process/src/main/java/org/sonar/process/logging/Log4JPropertiesBuilder.java index 8e83756002c..eccb7f5b3f5 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/logging/Log4JPropertiesBuilder.java +++ b/server/sonar-process/src/main/java/org/sonar/process/logging/Log4JPropertiesBuilder.java @@ -35,6 +35,7 @@ import static java.lang.String.valueOf; public class Log4JPropertiesBuilder extends AbstractLogHelper { private static final String ROOT_LOGGER_NAME = "rootLogger"; + private static final int UNLIMITED_MAX_FILES = 100_000; private final Properties log4j2Properties = new Properties(); private final Props props; @@ -94,6 +95,9 @@ public class Log4JPropertiesBuilder extends AbstractLogHelper { private RollingPolicy createRollingPolicy(File logDir, String filenamePrefix) { String rollingPolicy = props.value(ROLLING_POLICY_PROPERTY, "time:yyyy-MM-dd"); int maxFiles = props.valueAsInt(MAX_FILES_PROPERTY, 7); + if (maxFiles <= 0) { + maxFiles = UNLIMITED_MAX_FILES; + } if (rollingPolicy.startsWith("time:")) { return new TimeRollingPolicy(filenamePrefix, logDir, maxFiles, StringUtils.substringAfter(rollingPolicy, "time:")); diff --git a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java index 8df33a39273..4feda6aceaf 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/logging/Log4JPropertiesBuilderTest.java @@ -24,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.io.File; -import java.io.IOException; import java.util.HashSet; import java.util.Properties; import java.util.Random; @@ -131,7 +130,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_daily_time_rolling_policy_with_max_7_files_for_empty_props() throws IOException { + public void configureGlobalFileLog_sets_properties_for_daily_time_rolling_policy_with_max_7_files_for_empty_props() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); underTest.configureGlobalFileLog(esRootLoggerConfig, logDir, logPattern); @@ -140,7 +139,57 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_throws_MessageException_when_property_is_not_supported() throws IOException { + public void time_rolling_policy_has_large_max_files_if_property_is_zero() throws Exception { + File logDir = temporaryFolder.newFolder(); + String logPattern = "foo"; + Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( + ROLLING_POLICY_PROPERTY, "time:yyyy-MM-dd", + PROPERTY_MAX_FILES, "0"); + underTest.configureGlobalFileLog(esRootLoggerConfig, logDir, logPattern); + + verifyTimeRollingPolicy(underTest, logDir, logPattern, "yyyy-MM-dd", 100_000); + } + + @Test + public void time_rolling_policy_has_large_max_files_if_property_is_negative() throws Exception { + File logDir = temporaryFolder.newFolder(); + String logPattern = "foo"; + Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( + ROLLING_POLICY_PROPERTY, "time:yyyy-MM-dd", + PROPERTY_MAX_FILES, "-2"); + underTest.configureGlobalFileLog(esRootLoggerConfig, logDir, logPattern); + + verifyTimeRollingPolicy(underTest, logDir, logPattern, "yyyy-MM-dd", 100_000); + } + + @Test + public void size_rolling_policy_has_large_max_files_if_property_is_zero() throws Exception { + File logDir = temporaryFolder.newFolder(); + String logPattern = "foo"; + String sizePattern = "1KB"; + Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( + ROLLING_POLICY_PROPERTY, "size:" + sizePattern, + PROPERTY_MAX_FILES, "0"); + underTest.configureGlobalFileLog(esRootLoggerConfig, logDir, logPattern); + + verifySizeRollingPolicy(underTest, logDir, logPattern, sizePattern, 100_000); + } + + @Test + public void size_rolling_policy_has_large_max_files_if_property_is_negative() throws Exception { + File logDir = temporaryFolder.newFolder(); + String logPattern = "foo"; + String sizePattern = "1KB"; + Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( + ROLLING_POLICY_PROPERTY, "size:" + sizePattern, + PROPERTY_MAX_FILES, "-2"); + underTest.configureGlobalFileLog(esRootLoggerConfig, logDir, logPattern); + + verifySizeRollingPolicy(underTest, logDir, logPattern, sizePattern, 100_000); + } + + @Test + public void configureGlobalFileLog_throws_MessageException_when_property_is_not_supported() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); String invalidPropertyValue = randomAlphanumeric(3); @@ -154,7 +203,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_with_max_7_files_when_property_starts_with_time_colon() throws IOException { + public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_with_max_7_files_when_property_starts_with_time_colon() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); String timePattern = randomAlphanumeric(6); @@ -166,7 +215,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_when_property_starts_with_time_colon_and_specified_max_number_of_files() throws IOException { + public void configureGlobalFileLog_sets_properties_for_time_rolling_policy_when_property_starts_with_time_colon_and_specified_max_number_of_files() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); String timePattern = randomAlphanumeric(6); @@ -180,7 +229,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_with_max_7_files_when_property_starts_with_size_colon() throws IOException { + public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_with_max_7_files_when_property_starts_with_size_colon() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); String sizePattern = randomAlphanumeric(6); @@ -192,7 +241,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_when_property_starts_with_size_colon_and_specified_max_number_of_files() throws IOException { + public void configureGlobalFileLog_sets_properties_for_size_rolling_policy_when_property_starts_with_size_colon_and_specified_max_number_of_files() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); String sizePattern = randomAlphanumeric(6); @@ -206,7 +255,7 @@ public class Log4JPropertiesBuilderTest { } @Test - public void configureGlobalFileLog_sets_properties_for_no_rolling_policy_when_property_is_none() throws IOException { + public void configureGlobalFileLog_sets_properties_for_no_rolling_policy_when_property_is_none() throws Exception { File logDir = temporaryFolder.newFolder(); String logPattern = randomAlphanumeric(15); Log4JPropertiesBuilder underTest = newLog4JPropertiesBuilder( |