This is an automated email from the ASF dual-hosted git repository. klund pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
commit ff40e7d8fd26f48f56eb48c96ab3933b4a968206 Author: Kirk Lund <[email protected]> AuthorDate: Fri Oct 5 11:07:52 2018 -0700 GEODE-2644: Cleanup Marker Filter logging tests * Explode GeodeVerboseLogMarkerIntegrationTest into multiple classes. * Update tests to use Log4J2 LoggerContextRule. --- ...reVerboseMarkerFilterAcceptIntegrationTest.java | 95 +++++++++ ...fireVerboseMarkerFilterDenyIntegrationTest.java | 87 ++++++++ .../GeodeVerboseLogMarkerIntegrationTest.java | 221 --------------------- ...deVerboseMarkerFilterAcceptIntegrationTest.java | 96 +++++++++ ...eodeVerboseMarkerFilterDenyIntegrationTest.java | 96 +++++++++ ...oseMarkerFilterAcceptIntegrationTest_log4j2.xml | 35 ++++ ...rboseMarkerFilterDenyIntegrationTest_log4j2.xml | 35 ++++ ...oseMarkerFilterAcceptIntegrationTest_log4j2.xml | 35 ++++ ...rboseMarkerFilterDenyIntegrationTest_log4j2.xml | 35 ++++ .../logging/log4j/custom/BasicAppender.java | 74 ------- .../log4j/marker/log4j2-gemfire_verbose-accept.xml | 40 ---- .../log4j/marker/log4j2-gemfire_verbose-deny.xml | 40 ---- .../log4j/marker/log4j2-geode_verbose-accept.xml | 40 ---- .../log4j/marker/log4j2-geode_verbose-deny.xml | 40 ---- 14 files changed, 514 insertions(+), 455 deletions(-) diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest.java new file mode 100644 index 0000000..56f3855 --- /dev/null +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.logging.log4j; + +import static org.apache.geode.test.util.ResourceUtils.createFileFromResource; +import static org.apache.geode.test.util.ResourceUtils.getResource; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URL; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; + +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.test.junit.categories.LoggingTest; + +@Category(LoggingTest.class) +public class GemfireVerboseMarkerFilterAcceptIntegrationTest { + + private static final String APPENDER_NAME = "LIST"; + + private static String configFilePath; + + private Logger logger; + private String logMessage; + private ListAppender listAppender; + + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public LoggerContextRule loggerContextRule = new LoggerContextRule(configFilePath); + + @BeforeClass + public static void setUpLogConfigFile() throws Exception { + String configFileName = + GemfireVerboseMarkerFilterAcceptIntegrationTest.class.getSimpleName() + "_log4j2.xml"; + URL resource = getResource(configFileName); + configFilePath = createFileFromResource(resource, temporaryFolder.getRoot(), configFileName) + .getAbsolutePath(); + } + + @Before + public void setUp() throws Exception { + logger = LogService.getLogger(); + logMessage = "this is a log statement"; + + assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo()) + .isFalse(); + + listAppender = loggerContextRule.getListAppender(APPENDER_NAME); + } + + @Test + public void gemfireVerboseShouldLogIfGemfireVerboseIsAccept() { + logger.info(LogMarker.GEMFIRE_VERBOSE, logMessage); + + LogEvent logEvent = listAppender.getEvents().get(0); + assertThat(logEvent.getLoggerName()).isEqualTo(logger.getName()); + assertThat(logEvent.getLevel()).isEqualTo(Level.INFO); + assertThat(logEvent.getMessage().getFormattedMessage()).isEqualTo(logMessage); + } + + @Test + public void geodeVerboseShouldLogIfGemfireVerboseIsAccept() { + logger.info(LogMarker.GEODE_VERBOSE, logMessage); + + LogEvent logEvent = listAppender.getEvents().get(0); + assertThat(logEvent.getLoggerName()).isEqualTo(logger.getName()); + assertThat(logEvent.getLevel()).isEqualTo(Level.INFO); + assertThat(logEvent.getMessage().getFormattedMessage()).isEqualTo(logMessage); + } +} diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest.java new file mode 100644 index 0000000..87cec2f --- /dev/null +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.logging.log4j; + +import static org.apache.geode.test.util.ResourceUtils.createFileFromResource; +import static org.apache.geode.test.util.ResourceUtils.getResource; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URL; + +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; + +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.test.junit.categories.LoggingTest; + +@Category(LoggingTest.class) +public class GemfireVerboseMarkerFilterDenyIntegrationTest { + + private static final String APPENDER_NAME = "LIST"; + + private static String configFilePath; + + private Logger logger; + private String logMessage; + private ListAppender listAppender; + + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public LoggerContextRule loggerContextRule = new LoggerContextRule(configFilePath); + + @BeforeClass + public static void setUpLogConfigFile() throws Exception { + String configFileName = + GemfireVerboseMarkerFilterDenyIntegrationTest.class.getSimpleName() + "_log4j2.xml"; + URL resource = getResource(configFileName); + configFilePath = createFileFromResource(resource, temporaryFolder.getRoot(), configFileName) + .getAbsolutePath(); + } + + @Before + public void setUp() throws Exception { + logger = LogService.getLogger(); + logMessage = "this is a log statement"; + + assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo()) + .isFalse(); + + listAppender = loggerContextRule.getListAppender(APPENDER_NAME); + } + + @Test + public void gemfireVerboseShouldNotLogIfGemfireVerboseIsDeny() { + logger.info(LogMarker.GEMFIRE_VERBOSE, logMessage); + + assertThat(listAppender.getEvents()).isEmpty(); + } + + @Test + public void geodeVerboseShouldNotLogIfGemfireVerboseIsDeny() { + logger.info(LogMarker.GEODE_VERBOSE, logMessage); + + assertThat(listAppender.getEvents()).isEmpty(); + } +} diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java deleted file mode 100644 index 13d26b6..0000000 --- a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.internal.logging.log4j; - -import static org.apache.logging.log4j.core.config.ConfigurationFactory.CONFIGURATION_FILE_PROPERTY; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.status.StatusLogger; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.SystemErrRule; -import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.experimental.categories.Category; -import org.junit.rules.TemporaryFolder; -import org.junit.rules.TestName; - -import org.apache.geode.internal.logging.LogService; -import org.apache.geode.internal.logging.log4j.custom.BasicAppender; -import org.apache.geode.test.junit.categories.LoggingTest; - -/** - * Integration tests with accept and deny of GEODE_VERBOSE and GEMFIRE_VERBOSE. - */ -@Category(LoggingTest.class) -public class GeodeVerboseLogMarkerIntegrationTest { - - private static final String RESOURCE_PACKAGE = "/org/apache/geode/internal/logging/log4j/marker/"; - private static final String FILE_NAME_GEMFIRE_VERBOSE_ACCEPT = - "log4j2-gemfire_verbose-accept.xml"; - private static final String FILE_NAME_GEMFIRE_VERBOSE_DENY = "log4j2-gemfire_verbose-deny.xml"; - private static final String FILE_NAME_GEODE_VERBOSE_ACCEPT = "log4j2-geode_verbose-accept.xml"; - private static final String FILE_NAME_GEODE_VERBOSE_DENY = "log4j2-geode_verbose-deny.xml"; - - private String beforeConfigFileProp; - private Level beforeLevel; - - private File configFileGemfireVerboseAccept; - private File configFileGemfireVerboseDeny; - private File configFileGeodeVerboseAccept; - private File configFileGeodeVerboseDeny; - - @Rule - public SystemErrRule systemErrRule = new SystemErrRule().enableLog(); - @Rule - public SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - @Rule - public TestName testName = new TestName(); - - @Before - public void preAssertions() { - assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEMFIRE_VERBOSE_ACCEPT)) - .isNotNull(); - assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEMFIRE_VERBOSE_DENY)) - .isNotNull(); - assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEODE_VERBOSE_ACCEPT)) - .isNotNull(); - assertThat(getClass().getResource(RESOURCE_PACKAGE + FILE_NAME_GEODE_VERBOSE_DENY)).isNotNull(); - } - - @Before - public void setUp() throws Exception { - Configurator.shutdown(); - BasicAppender.clearInstance(); - - beforeConfigFileProp = System.getProperty(CONFIGURATION_FILE_PROPERTY); - beforeLevel = StatusLogger.getLogger().getLevel(); - - configFileGemfireVerboseAccept = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_ACCEPT); - configFileGemfireVerboseDeny = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_DENY); - configFileGeodeVerboseAccept = createConfigFile(FILE_NAME_GEODE_VERBOSE_ACCEPT); - configFileGeodeVerboseDeny = createConfigFile(FILE_NAME_GEODE_VERBOSE_DENY); - } - - @After - public void tearDown() throws Exception { - Configurator.shutdown(); - - System.clearProperty(CONFIGURATION_FILE_PROPERTY); - if (beforeConfigFileProp != null) { - System.setProperty(CONFIGURATION_FILE_PROPERTY, beforeConfigFileProp); - } - StatusLogger.getLogger().setLevel(beforeLevel); - - LogService.reconfigure(); - assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo()) - .isTrue(); - - BasicAppender.clearInstance(); - - assertThat(systemErrRule.getLog()).isEmpty(); - } - - @Test - public void geodeVerboseShouldLogIfGeodeVerboseIsAccept() { - configureLogging(configFileGeodeVerboseAccept); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEODE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).contains(msg); - } - - @Test - public void geodeVerboseShouldNotLogIfGeodeVerboseIsDeny() { - configureLogging(configFileGeodeVerboseDeny); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEODE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).doesNotContain(msg); - } - - @Test - public void geodeVerboseShouldLogIfGemfireVerboseIsAccept() { - configureLogging(configFileGemfireVerboseAccept); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEODE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).contains(msg); - } - - @Test - public void geodeVerboseShouldNotLogIfGemfireVerboseIsDeny() { - configureLogging(configFileGemfireVerboseDeny); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEODE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).doesNotContain(msg); - } - - /** - * GEMFIRE_VERBOSE is parent of GEODE_VERBOSE so enabling GEODE_VERBOSE does not enable - * GEMFIRE_VERBOSE. - */ - @Test - public void gemfireVerboseShouldNotLogIfGeodeVerboseIsAccept() { - configureLogging(configFileGeodeVerboseAccept); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEMFIRE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).doesNotContain(msg); - } - - /** - * GEMFIRE_VERBOSE is parent of GEODE_VERBOSE so disabling GEODE_VERBOSE does not disable - * GEMFIRE_VERBOSE. - */ - @Test - public void gemfireVerboseShouldLogIfGeodeVerboseIsDeny() { - configureLogging(configFileGeodeVerboseDeny); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEMFIRE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).contains(msg); - } - - @Test - public void gemfireVerboseShouldLogIfGemfireVerboseIsAccept() { - configureLogging(configFileGemfireVerboseAccept); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEMFIRE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).contains(msg); - } - - @Test - public void gemfireVerboseShouldNotLogIfGemfireVerboseIsDeny() { - configureLogging(configFileGemfireVerboseDeny); - Logger logger = LogService.getLogger(); - - String msg = testName.getMethodName(); - logger.info(LogMarker.GEMFIRE_VERBOSE, msg); - - assertThat(systemOutRule.getLog()).doesNotContain(msg); - } - - private File createConfigFile(final String name) throws IOException, URISyntaxException { - assertThat(getClass().getResource(RESOURCE_PACKAGE + name)).isNotNull(); - return new Configuration(getClass().getResource(RESOURCE_PACKAGE + name), name) - .createConfigFileIn(temporaryFolder.getRoot()); - } - - private void configureLogging(final File configFile) { - System.setProperty(CONFIGURATION_FILE_PROPERTY, configFile.getAbsolutePath()); - LogService.reconfigure(); - } -} diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest.java new file mode 100644 index 0000000..00c8da1 --- /dev/null +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.logging.log4j; + +import static org.apache.geode.test.util.ResourceUtils.createFileFromResource; +import static org.apache.geode.test.util.ResourceUtils.getResource; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URL; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; + +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.test.junit.categories.LoggingTest; + +@Category(LoggingTest.class) +public class GeodeVerboseMarkerFilterAcceptIntegrationTest { + + private static final String APPENDER_NAME = "LIST"; + + private static String configFilePath; + + private Logger logger; + private String logMessage; + private ListAppender listAppender; + + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public LoggerContextRule loggerContextRule = new LoggerContextRule(configFilePath); + + @BeforeClass + public static void setUpLogConfigFile() throws Exception { + String configFileName = + GeodeVerboseMarkerFilterAcceptIntegrationTest.class.getSimpleName() + "_log4j2.xml"; + URL resource = getResource(configFileName); + configFilePath = createFileFromResource(resource, temporaryFolder.getRoot(), configFileName) + .getAbsolutePath(); + } + + @Before + public void setUp() throws Exception { + logger = LogService.getLogger(); + logMessage = "this is a log statement"; + + assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo()) + .isFalse(); + + listAppender = loggerContextRule.getListAppender(APPENDER_NAME); + } + + @Test + public void geodeVerboseShouldLogIfGeodeVerboseIsAccept() { + logger.info(LogMarker.GEODE_VERBOSE, logMessage); + + LogEvent logEvent = listAppender.getEvents().get(0); + assertThat(logEvent.getLoggerName()).isEqualTo(logger.getName()); + assertThat(logEvent.getLevel()).isEqualTo(Level.INFO); + assertThat(logEvent.getMessage().getFormattedMessage()).isEqualTo(logMessage); + } + + /** + * GEMFIRE_VERBOSE is parent of GEODE_VERBOSE so enabling GEODE_VERBOSE does not enable + * GEMFIRE_VERBOSE. + */ + @Test + public void gemfireVerboseShouldNotLogIfGeodeVerboseIsAccept() { + logger.info(LogMarker.GEMFIRE_VERBOSE, logMessage); + + assertThat(listAppender.getEvents()).isEmpty(); + } +} diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest.java new file mode 100644 index 0000000..99a00ae --- /dev/null +++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.geode.internal.logging.log4j; + +import static org.apache.geode.test.util.ResourceUtils.createFileFromResource; +import static org.apache.geode.test.util.ResourceUtils.getResource; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.URL; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.junit.LoggerContextRule; +import org.apache.logging.log4j.test.appender.ListAppender; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TemporaryFolder; + +import org.apache.geode.internal.logging.LogService; +import org.apache.geode.test.junit.categories.LoggingTest; + +@Category(LoggingTest.class) +public class GeodeVerboseMarkerFilterDenyIntegrationTest { + + private static final String APPENDER_NAME = "LIST"; + + private static String configFilePath; + + private Logger logger; + private String logMessage; + private ListAppender listAppender; + + @ClassRule + public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public LoggerContextRule loggerContextRule = new LoggerContextRule(configFilePath); + + @BeforeClass + public static void setUpLogConfigFile() throws Exception { + String configFileName = + GeodeVerboseMarkerFilterDenyIntegrationTest.class.getSimpleName() + "_log4j2.xml"; + URL resource = getResource(configFileName); + configFilePath = createFileFromResource(resource, temporaryFolder.getRoot(), configFileName) + .getAbsolutePath(); + } + + @Before + public void setUp() throws Exception { + logger = LogService.getLogger(); + logMessage = "this is a log statement"; + + assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigurationInfo()) + .isFalse(); + + listAppender = loggerContextRule.getListAppender(APPENDER_NAME); + } + + @Test + public void geodeVerboseShouldNotLogIfGeodeVerboseIsDeny() { + logger.info(LogMarker.GEODE_VERBOSE, logMessage); + + assertThat(listAppender.getEvents()).isEmpty(); + } + + /** + * GEMFIRE_VERBOSE is parent of GEODE_VERBOSE so disabling GEODE_VERBOSE does not disable + * GEMFIRE_VERBOSE. + */ + @Test + public void gemfireVerboseShouldLogIfGeodeVerboseIsDeny() { + logger.info(LogMarker.GEMFIRE_VERBOSE, logMessage); + + LogEvent logEvent = listAppender.getEvents().get(0); + assertThat(logEvent.getLoggerName()).isEqualTo(logger.getName()); + assertThat(logEvent.getLevel()).isEqualTo(Level.INFO); + assertThat(logEvent.getMessage().getFormattedMessage()).isEqualTo(logMessage); + } +} diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml new file mode 100644 index 0000000..2d6534a --- /dev/null +++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more contributor license + ~ agreements. See the NOTICE file distributed with this work for additional information regarding + ~ copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance with the License. You may obtain a + ~ copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software distributed under the License + ~ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + ~ or implied. See the License for the specific language governing permissions and limitations under + ~ the License. + --> +<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> + <Properties> + <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> + </Properties> + <Appenders> + <List name="LIST"/> + </Appenders> + <Loggers> + <Logger name="com.gemstone" level="INFO" additivity="true"/> + <Logger name="org.apache.geode" level="INFO" additivity="true"> + <filters> + <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="ACCEPT" onMismatch="DENY"/> + </filters> + </Logger> + <Logger name="org.jgroups" level="FATAL" additivity="true"/> + <Root level="INFO"> + <AppenderRef ref="LIST"/> + </Root> + </Loggers> +</Configuration> diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest_log4j2.xml new file mode 100644 index 0000000..8509b41 --- /dev/null +++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GemfireVerboseMarkerFilterDenyIntegrationTest_log4j2.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more contributor license + ~ agreements. See the NOTICE file distributed with this work for additional information regarding + ~ copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance with the License. You may obtain a + ~ copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software distributed under the License + ~ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + ~ or implied. See the License for the specific language governing permissions and limitations under + ~ the License. + --> +<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> + <Properties> + <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> + </Properties> + <Appenders> + <List name="LIST"/> + </Appenders> + <Loggers> + <Logger name="com.gemstone" level="INFO" additivity="true"/> + <Logger name="org.apache.geode" level="INFO" additivity="true"> + <filters> + <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="DENY" onMismatch="ACCEPT"/> + </filters> + </Logger> + <Logger name="org.jgroups" level="FATAL" additivity="true"/> + <Root level="INFO"> + <AppenderRef ref="LIST"/> + </Root> + </Loggers> +</Configuration> diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml new file mode 100644 index 0000000..f73ea4b --- /dev/null +++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterAcceptIntegrationTest_log4j2.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more contributor license + ~ agreements. See the NOTICE file distributed with this work for additional information regarding + ~ copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance with the License. You may obtain a + ~ copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software distributed under the License + ~ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + ~ or implied. See the License for the specific language governing permissions and limitations under + ~ the License. + --> +<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> + <Properties> + <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> + </Properties> + <Appenders> + <List name="LIST"/> + </Appenders> + <Loggers> + <Logger name="com.gemstone" level="INFO" additivity="true"/> + <Logger name="org.apache.geode" level="INFO" additivity="true"> + <filters> + <MarkerFilter marker="GEODE_VERBOSE" onMatch="ACCEPT" onMismatch="DENY"/> + </filters> + </Logger> + <Logger name="org.jgroups" level="FATAL" additivity="true"/> + <Root level="INFO"> + <AppenderRef ref="LIST"/> + </Root> + </Loggers> +</Configuration> diff --git a/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest_log4j2.xml b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest_log4j2.xml new file mode 100644 index 0000000..5a32d9c --- /dev/null +++ b/geode-core/src/integrationTest/resources/org/apache/geode/internal/logging/log4j/GeodeVerboseMarkerFilterDenyIntegrationTest_log4j2.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one or more contributor license + ~ agreements. See the NOTICE file distributed with this work for additional information regarding + ~ copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance with the License. You may obtain a + ~ copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software distributed under the License + ~ is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + ~ or implied. See the License for the specific language governing permissions and limitations under + ~ the License. + --> +<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> + <Properties> + <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> + </Properties> + <Appenders> + <List name="LIST"/> + </Appenders> + <Loggers> + <Logger name="com.gemstone" level="INFO" additivity="true"/> + <Logger name="org.apache.geode" level="INFO" additivity="true"> + <filters> + <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="ACCEPT"/> + </filters> + </Logger> + <Logger name="org.jgroups" level="FATAL" additivity="true"/> + <Root level="INFO"> + <AppenderRef ref="LIST"/> + </Root> + </Loggers> +</Configuration> diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/BasicAppender.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/BasicAppender.java deleted file mode 100644 index 22afc5d..0000000 --- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/custom/BasicAppender.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more contributor license - * agreements. See the NOTICE file distributed with this work for additional information regarding - * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. You may obtain a - * copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.internal.logging.log4j.custom; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import org.apache.logging.log4j.core.Filter; -import org.apache.logging.log4j.core.Layout; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.appender.AbstractAppender; -import org.apache.logging.log4j.core.config.plugins.Plugin; -import org.apache.logging.log4j.core.config.plugins.PluginAttribute; -import org.apache.logging.log4j.core.config.plugins.PluginElement; -import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.layout.PatternLayout; - -@Plugin(name = "Basic", category = "Core", elementType = "appender", printObject = true) -public class BasicAppender extends AbstractAppender { - - private static volatile BasicAppender instance; - - private final List<LogEvent> events = new ArrayList<>(); - - public BasicAppender(final String name, final Filter filter, - final Layout<? extends Serializable> layout) { - super(name, filter, layout); - } - - @PluginFactory - public static BasicAppender createAppender(@PluginAttribute("name") String name, - @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, - @PluginElement("Layout") Layout layout, @PluginElement("Filters") Filter filter) { - if (layout == null) { - layout = PatternLayout.createDefaultLayout(); - } - instance = new BasicAppender(name, filter, layout); - return instance; - } - - public static BasicAppender getInstance() { - return instance; - } - - public static void clearInstance() { - instance = null; - } - - public static void clearEvents() { - instance.events.clear(); - } - - @Override - public void append(final LogEvent event) { - this.events.add(event); - } - - public List<LogEvent> events() { - return this.events; - } -} diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml deleted file mode 100644 index a581793..0000000 --- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You under the Apache License, Version 2.0 - ~ (the "License"); you may not use this file except in compliance with - ~ the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> - <Properties> - <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> - <Property name="geode-default">true</Property> - </Properties> - <Appenders> - <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="${geode-pattern}"/> - </Console> - </Appenders> - <Loggers> - <Logger name="com.gemstone" level="INFO" additivity="true"/> - <Logger name="org.apache.geode" level="INFO" additivity="true"> - <filters> - <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="ACCEPT" onMismatch="DENY"/> - </filters> - </Logger> - <Logger name="org.jgroups" level="FATAL" additivity="true"/> - <Root level="INFO"> - <AppenderRef ref="STDOUT"/> - </Root> - </Loggers> -</Configuration> diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml deleted file mode 100644 index bb5b2f6..0000000 --- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You under the Apache License, Version 2.0 - ~ (the "License"); you may not use this file except in compliance with - ~ the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> - <Properties> - <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> - <Property name="geode-default">true</Property> - </Properties> - <Appenders> - <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="${geode-pattern}"/> - </Console> - </Appenders> - <Loggers> - <Logger name="com.gemstone" level="INFO" additivity="true"/> - <Logger name="org.apache.geode" level="INFO" additivity="true"> - <filters> - <MarkerFilter marker="GEMFIRE_VERBOSE" onMatch="DENY" onMismatch="ACCEPT"/> - </filters> - </Logger> - <Logger name="org.jgroups" level="FATAL" additivity="true"/> - <Root level="INFO"> - <AppenderRef ref="STDOUT"/> - </Root> - </Loggers> -</Configuration> diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml deleted file mode 100644 index 55b24e5..0000000 --- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You under the Apache License, Version 2.0 - ~ (the "License"); you may not use this file except in compliance with - ~ the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> - <Properties> - <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> - <Property name="geode-default">true</Property> - </Properties> - <Appenders> - <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="${geode-pattern}"/> - </Console> - </Appenders> - <Loggers> - <Logger name="com.gemstone" level="INFO" additivity="true"/> - <Logger name="org.apache.geode" level="INFO" additivity="true"> - <filters> - <MarkerFilter marker="GEODE_VERBOSE" onMatch="ACCEPT" onMismatch="DENY"/> - </filters> - </Logger> - <Logger name="org.jgroups" level="FATAL" additivity="true"/> - <Root level="INFO"> - <AppenderRef ref="STDOUT"/> - </Root> - </Loggers> -</Configuration> diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml deleted file mode 100644 index a45f6af..0000000 --- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one or more - ~ contributor license agreements. See the NOTICE file distributed with - ~ this work for additional information regarding copyright ownership. - ~ The ASF licenses this file to You under the Apache License, Version 2.0 - ~ (the "License"); you may not use this file except in compliance with - ~ the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, software - ~ distributed under the License is distributed on an "AS IS" BASIS, - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - ~ See the License for the specific language governing permissions and - ~ limitations under the License. - --> -<Configuration status="WARN" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j"> - <Properties> - <Property name="geode-pattern">[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%hexTid] %message%n%throwable%n</Property> - <Property name="geode-default">true</Property> - </Properties> - <Appenders> - <Console name="STDOUT" target="SYSTEM_OUT"> - <PatternLayout pattern="${geode-pattern}"/> - </Console> - </Appenders> - <Loggers> - <Logger name="com.gemstone" level="INFO" additivity="true"/> - <Logger name="org.apache.geode" level="INFO" additivity="true"> - <filters> - <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="ACCEPT"/> - </filters> - </Logger> - <Logger name="org.jgroups" level="FATAL" additivity="true"/> - <Root level="INFO"> - <AppenderRef ref="STDOUT"/> - </Root> - </Loggers> -</Configuration>
