You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/10/04 20:14:10 UTC
[1/3] incubator-geode git commit: GEODE-1902: reformat code
Repository: incubator-geode
Updated Branches:
refs/heads/develop 8929e93bd -> 375c6c5bc
GEODE-1902: reformat code
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8703f2a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8703f2a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8703f2a7
Branch: refs/heads/develop
Commit: 8703f2a71526a35f8945698611d18a0b8b9bd373
Parents: c80cba2
Author: Kirk Lund <kl...@apache.org>
Authored: Tue Oct 4 11:45:46 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Oct 4 13:14:19 2016 -0700
----------------------------------------------------------------------
.../geode/internal/logging/LogService.java | 35 +++++++--------
.../internal/logging/log4j/Configurator.java | 20 ++-------
.../geode/internal/logging/log4j/LogMarker.java | 45 ++++++++------------
.../logging/log4j/LogMarkerJUnitTest.java | 6 +--
4 files changed, 40 insertions(+), 66 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8703f2a7/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
index 405434d..baf01e1 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
@@ -54,8 +54,11 @@ public class LogService extends LogManager {
public static final String GEMFIRE_VERBOSE_FILTER = "{GEMFIRE_VERBOSE}";
public static final String DEFAULT_CONFIG = "/log4j2.xml";
public static final String CLI_CONFIG = "/log4j2-cli.xml";
+
protected static final String STDOUT = "STDOUT";
+
private static final PropertyChangeListener propertyChangeListener = new PropertyChangeListenerImpl();
+
/**
* Name of variable that is set to "true" in log4j2.xml to indicate that it is the default geode config xml.
*/
@@ -75,8 +78,7 @@ public class LogService extends LogManager {
}
private static void init() {
- LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
- .getContext();
+ LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext();
context.removePropertyChangeListener(propertyChangeListener);
context.addPropertyChangeListener(propertyChangeListener);
context.reconfigure(); // propertyChangeListener invokes configureFastLoggerDelegating
@@ -107,9 +109,7 @@ public class LogService extends LogManager {
}
public static boolean isUsingGemFireDefaultConfig() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
- .getContext()
- .getConfiguration();
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
final StrSubstitutor sub = config.getStrSubstitutor();
final StrLookup resolver = sub.getVariableResolver();
@@ -127,6 +127,7 @@ public class LogService extends LogManager {
* Finds a Log4j configuration file in the current directory. The names of
* the files to look for are the same as those that Log4j would look for on
* the classpath.
+ *
* @return A File for the configuration file or null if one isn't found.
*/
public static File findLog4jConfigInCurrentDir() {
@@ -135,6 +136,7 @@ public class LogService extends LogManager {
/**
* Returns a Logger with the name of the calling class.
+ *
* @return The Logger for the calling class.
*/
public static Logger getLogger() {
@@ -152,16 +154,16 @@ public class LogService extends LogManager {
* This is the bridge to LogWriter and LogWriterI18n that we need to eventually
* stop using in phase 1. We will switch over from a shared LogWriterLogger instance
* to having every GemFire class own its own private static GemFireLogger
+ *
* @return The LogWriterLogger for the calling class.
*/
- public static LogWriterLogger createLogWriterLogger(final String name,
- final String connectionName,
- final boolean isSecure) {
+ public static LogWriterLogger createLogWriterLogger(final String name, final String connectionName, final boolean isSecure) {
return LogWriterLogger.create(name, connectionName, isSecure);
}
/**
* Return the Log4j Level associated with the int level.
+ *
* @param intLevel The int value of the Level to return.
*
* @return The Level.
@@ -180,6 +182,7 @@ public class LogService extends LogManager {
/**
* Gets the class name of the caller in the current stack at the given {@code depth}.
+ *
* @param depth a 0-based index in the current stack.
*
* @return a class name
@@ -189,19 +192,14 @@ public class LogService extends LogManager {
}
public static Configuration getConfiguration() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
- .getContext()
- .getConfiguration();
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
return config;
}
public static void configureFastLoggerDelegating() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
- .getContext()
- .getConfiguration();
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
- if (Configurator.hasContextWideFilter(config) || Configurator.hasAppenderFilter(config) || Configurator.hasDebugOrLower(config) || Configurator
- .hasLoggerFilter(config) || Configurator.hasAppenderRefFilter(config)) {
+ if (Configurator.hasContextWideFilter(config) || Configurator.hasAppenderFilter(config) || Configurator.hasDebugOrLower(config) || Configurator.hasLoggerFilter(config) || Configurator.hasAppenderRefFilter(config)) {
FastLogger.setDelegating(true);
} else {
FastLogger.setDelegating(false);
@@ -266,11 +264,10 @@ public class LogService extends LogManager {
private static class PropertyChangeListenerImpl implements PropertyChangeListener {
- @SuppressWarnings("synthetic-access")
@Override
+ @SuppressWarnings("synthetic-access")
public void propertyChange(final PropertyChangeEvent evt) {
- StatusLogger.getLogger()
- .debug("LogService responding to a property change event. Property name is {}.", evt.getPropertyName());
+ StatusLogger.getLogger().debug("LogService responding to a property change event. Property name is {}.", evt.getPropertyName());
if (evt.getPropertyName().equals(LoggerContext.PROPERTY_CONFIG)) {
configureFastLoggerDelegating();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8703f2a7/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
index fb942b8..6630832 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
@@ -38,20 +38,12 @@ import org.apache.geode.internal.logging.LogService;
*/
public class Configurator {
- /*public static void reconfigure() {
- LoggerContext context = (LoggerContext)LogManager.getContext(false);
- context.updateLoggers();
- //context.reconfigure();
- }*/
-
public static void shutdown() {
- //LoggerContext context = (LoggerContext)LogManager.getContext(false);
final LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).getContext();
context.stop();
org.apache.logging.log4j.core.config.Configurator.shutdown(context);
}
-
public static void setLevel(String name, Level level) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
LoggerConfig logConfig = getLoggerConfig(name);
@@ -78,9 +70,7 @@ public class Configurator {
List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
Map<Property, Boolean> properties = logConfig.getProperties();
Set<Property> props = properties == null ? null : properties.keySet();
- logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()), logConfig.getLevel(), name, String.valueOf(logConfig
- .isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props
- .toArray(new Property[props.size()]), config, null);
+ logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()), logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props.toArray(new Property[props.size()]), config, null);
config.addLogger(name, logConfig);
update = true;
}
@@ -99,9 +89,7 @@ public class Configurator {
List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
Map<Property, Boolean> properties = logConfig.getProperties();
Set<Property> props = properties == null ? null : properties.keySet();
- logConfig = LoggerConfig.createLogger(String.valueOf(additive), logConfig.getLevel(), name, String.valueOf(logConfig
- .isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props
- .toArray(new Property[props.size()]), config, null);
+ logConfig = LoggerConfig.createLogger(String.valueOf(additive), logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props.toArray(new Property[props.size()]), config, null);
config.addLogger(name, logConfig);
update = true;
}
@@ -159,9 +147,7 @@ public class Configurator {
boolean isRoot = loggerConfig.getName().equals("");
boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
boolean hasFilter = loggerConfig.hasFilter();
- boolean isGemFireVerboseFilter = hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter()
- .toString()) || LogService.GEMFIRE_VERBOSE_FILTER
- .equals(loggerConfig.getFilter().toString()));
+ boolean isGemFireVerboseFilter = hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()) || LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()));
if (isRoot || isGemFire) {
// check for Logger Filter
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8703f2a7/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
index 42b5b17..cbc3848 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
@@ -26,12 +26,15 @@ import org.apache.geode.DataSerializable;
public interface LogMarker {
/**
+ * @deprecated GEMFIRE_VERBOSE is deprecated in favor of GEODE_VERBOSE
+ */
+ @Deprecated
+ public static final Marker GEMFIRE_VERBOSE = MarkerManager.getMarker("GEMFIRE_VERBOSE");
+
+ /**
* GEODE_VERBOSE is a parent to all other markers so that they can all be turned off with<br>
* <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
- * <p>
- * GEMFIRE_VERBOSE will be deprecated in the near future
*/
- public static final Marker GEMFIRE_VERBOSE = MarkerManager.getMarker("GEMFIRE_VERBOSE");
public static final Marker GEODE_VERBOSE = MarkerManager.getMarker("GEODE_VERBOSE").setParents(GEMFIRE_VERBOSE);
public static final Marker BRIDGE_SERVER = MarkerManager.getMarker("BRIDGE_SERVER").addParents(GEODE_VERBOSE);
@@ -47,22 +50,17 @@ public interface LogMarker {
public static final Marker TOMBSTONE_COUNT = MarkerManager.getMarker("TOMBSTONE_COUNT").addParents(TOMBSTONE);
public static final Marker LRU = MarkerManager.getMarker("LRU").addParents(GEODE_VERBOSE);
- public static final Marker LRU_TOMBSTONE_COUNT = MarkerManager.getMarker("LRU_TOMBSTONE_COUNT")
- .addParents(LRU, TOMBSTONE_COUNT);
+ public static final Marker LRU_TOMBSTONE_COUNT = MarkerManager.getMarker("LRU_TOMBSTONE_COUNT").addParents(LRU, TOMBSTONE_COUNT);
public static final Marker LRU_CLOCK = MarkerManager.getMarker("LRU_CLOCK").addParents(LRU);
public static final Marker RVV = MarkerManager.getMarker("RVV").addParents(GEODE_VERBOSE);
- public static final Marker VERSION_TAG = MarkerManager.getMarker("VERSION_TAG")
- .addParents(GEODE_VERBOSE); // gemfire.VersionTag.DEBUG
- public static final Marker VERSIONED_OBJECT_LIST = MarkerManager.getMarker("VERSIONED_OBJECT_LIST")
- .addParents(GEODE_VERBOSE); // gemfire.VersionedObjectList.DEBUG
+ public static final Marker VERSION_TAG = MarkerManager.getMarker("VERSION_TAG").addParents(GEODE_VERBOSE); // gemfire.VersionTag.DEBUG
+ public static final Marker VERSIONED_OBJECT_LIST = MarkerManager.getMarker("VERSIONED_OBJECT_LIST").addParents(GEODE_VERBOSE); // gemfire.VersionedObjectList.DEBUG
// cache.tier.sockets
- public static final Marker OBJECT_PART_LIST = MarkerManager.getMarker("OBJECT_PART_LIST")
- .addParents(GEODE_VERBOSE); // gemfire.ObjectPartList.DEBUG
+ public static final Marker OBJECT_PART_LIST = MarkerManager.getMarker("OBJECT_PART_LIST").addParents(GEODE_VERBOSE); // gemfire.ObjectPartList.DEBUG
- public static final Marker SERIALIZER = MarkerManager.getMarker("SERIALIZER")
- .addParents(GEODE_VERBOSE); // DataSerializer.DEBUG
+ public static final Marker SERIALIZER = MarkerManager.getMarker("SERIALIZER").addParents(GEODE_VERBOSE); // DataSerializer.DEBUG
/**
* If the <code>"DataSerializer.DUMP_SERIALIZED"</code> system
* property is set, the class names of the objects that are
@@ -72,23 +70,17 @@ public interface LogMarker {
* DataSerializable} (or should be special cased by a custom
* <code>DataSerializer</code>).
*/
- public static final Marker DUMP_SERIALIZED = MarkerManager.getMarker("DUMP_SERIALIZED")
- .addParents(SERIALIZER); // DataSerializer.DUMP_SERIALIZED
- public static final Marker TRACE_SERIALIZABLE = MarkerManager.getMarker("TRACE_SERIALIZABLE")
- .addParents(SERIALIZER); // DataSerializer.TRACE_SERIALIZABLE
- public static final Marker DEBUG_DSFID = MarkerManager.getMarker("DEBUG_DSFID")
- .addParents(SERIALIZER); // DataSerializer.DEBUG_DSFID
+ public static final Marker DUMP_SERIALIZED = MarkerManager.getMarker("DUMP_SERIALIZED").addParents(SERIALIZER); // DataSerializer.DUMP_SERIALIZED
+ public static final Marker TRACE_SERIALIZABLE = MarkerManager.getMarker("TRACE_SERIALIZABLE").addParents(SERIALIZER); // DataSerializer.TRACE_SERIALIZABLE
+ public static final Marker DEBUG_DSFID = MarkerManager.getMarker("DEBUG_DSFID").addParents(SERIALIZER); // DataSerializer.DEBUG_DSFID
public static final Marker STATISTICS = MarkerManager.getMarker("STATISTICS").addParents(GEODE_VERBOSE);
public static final Marker STATE_FLUSH_OP = MarkerManager.getMarker("STATE_FLUSH_OP").addParents(GEODE_VERBOSE);
public static final Marker DISTRIBUTION = MarkerManager.getMarker("DISTRIBUTION").addParents(GEODE_VERBOSE);
- public static final Marker DISTRIBUTION_STATE_FLUSH_OP = MarkerManager.getMarker("DISTRIBUTION_STATE_FLUSH_OP")
- .addParents(DISTRIBUTION, STATE_FLUSH_OP);
- public static final Marker DISTRIBUTION_BRIDGE_SERVER = MarkerManager.getMarker("DISTRIBUTION_BRIDGE_SERVER")
- .addParents(DISTRIBUTION, BRIDGE_SERVER);
- public static final Marker DISTRIBUTION_VIEWS = MarkerManager.getMarker("DISTRIBUTION_VIEWS")
- .addParents(DISTRIBUTION);
+ public static final Marker DISTRIBUTION_STATE_FLUSH_OP = MarkerManager.getMarker("DISTRIBUTION_STATE_FLUSH_OP").addParents(DISTRIBUTION, STATE_FLUSH_OP);
+ public static final Marker DISTRIBUTION_BRIDGE_SERVER = MarkerManager.getMarker("DISTRIBUTION_BRIDGE_SERVER").addParents(DISTRIBUTION, BRIDGE_SERVER);
+ public static final Marker DISTRIBUTION_VIEWS = MarkerManager.getMarker("DISTRIBUTION_VIEWS").addParents(DISTRIBUTION);
public static final Marker DM = MarkerManager.getMarker("DM").addParents(DISTRIBUTION);
public static final Marker DM_BRIDGE_SERVER = MarkerManager.getMarker("DM_BRIDGE").addParents(BRIDGE_SERVER, DM);
public static final Marker DA = MarkerManager.getMarker("DA").addParents(DISTRIBUTION);
@@ -111,6 +103,5 @@ public interface LogMarker {
public static final Marker MANAGED_ENTITY = MarkerManager.getMarker("MANAGED_ENTITY").addParents(GEODE_VERBOSE);
public static final Marker CACHE_XML = MarkerManager.getMarker("CACHE_XML").addParents(GEODE_VERBOSE);
- public static final Marker CACHE_XML_PARSER = MarkerManager.getMarker("CACHE_XML_PARSER")
- .addParents(GEODE_VERBOSE, CACHE_XML);
+ public static final Marker CACHE_XML_PARSER = MarkerManager.getMarker("CACHE_XML_PARSER").addParents(GEODE_VERBOSE, CACHE_XML);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8703f2a7/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
index 3077180..ec9d257 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
@@ -16,7 +16,6 @@
*/
package org.apache.geode.internal.logging.log4j;
-
import static org.apache.geode.internal.logging.log4j.custom.CustomConfiguration.*;
import static org.assertj.core.api.Assertions.*;
@@ -45,14 +44,15 @@ import org.apache.geode.test.junit.categories.IntegrationTest;
@Category(IntegrationTest.class)
public class LogMarkerJUnitTest {
+ private String beforeConfigFileProp;
+ private Level beforeLevel;
+
@Rule
public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
@Rule
public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
- private String beforeConfigFileProp;
- private Level beforeLevel;
@Before
public void setUp() throws Exception {
[3/3] incubator-geode git commit: GEODE-1902: add ACCEPT and DENY
tests for GEODE_VERBOSE and GEMFIRE_VERBOSE
Posted by kl...@apache.org.
GEODE-1902: add ACCEPT and DENY tests for GEODE_VERBOSE and GEMFIRE_VERBOSE
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/375c6c5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/375c6c5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/375c6c5b
Branch: refs/heads/develop
Commit: 375c6c5bcf3ee4ab52bb6bf4b34ca3eb26065ef9
Parents: 8703f2a
Author: Kirk Lund <kl...@apache.org>
Authored: Tue Oct 4 13:11:03 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Oct 4 13:14:20 2016 -0700
----------------------------------------------------------------------
.../internal/logging/log4j/Configuration.java | 29 +++
.../GeodeVerboseLogMarkerIntegrationTest.java | 217 +++++++++++++++++++
.../logging/log4j/LogMarkerJUnitTest.java | 112 ----------
.../marker/log4j2-gemfire_verbose-accept.xml | 24 ++
.../marker/log4j2-gemfire_verbose-deny.xml | 24 ++
.../marker/log4j2-geode_verbose-accept.xml | 24 ++
.../log4j/marker/log4j2-geode_verbose-deny.xml | 24 ++
7 files changed, 342 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/Configuration.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/Configuration.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/Configuration.java
new file mode 100644
index 0000000..8f7ca1a
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/Configuration.java
@@ -0,0 +1,29 @@
+package org.apache.geode.internal.logging.log4j;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+
+public class Configuration {
+
+ private URL resource;
+ private String configFileName;
+
+ public Configuration(final URL resource, final String configFileName) {
+ this.resource = resource;
+ this.configFileName = configFileName;
+ }
+
+ public File createConfigFileIn(final File targetFolder) throws IOException, URISyntaxException {
+ File targetFile = new File(targetFolder, this.configFileName);
+ IOUtils.copy(this.resource.openStream(), new FileOutputStream(targetFile));
+ assertThat(targetFile).hasSameContentAs(new File(this.resource.toURI()));
+ return targetFile;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
new file mode 100644
index 0000000..c6f7b96
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/GeodeVerboseLogMarkerIntegrationTest.java
@@ -0,0 +1,217 @@
+/*
+ * 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.assertj.core.api.Assertions.*;
+
+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.core.config.ConfigurationFactory;
+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.IntegrationTest;
+
+/**
+ * Integration tests with accept and deny of GEODE_VERBOSE and GEMFIRE_VERBOSE.
+ */
+@Category(IntegrationTest.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() throws Exception {
+ 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();
+
+ this.beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ this.beforeLevel = StatusLogger.getLogger().getLevel();
+
+ this.configFileGemfireVerboseAccept = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_ACCEPT);
+ this.configFileGemfireVerboseDeny = createConfigFile(FILE_NAME_GEMFIRE_VERBOSE_DENY);
+ this.configFileGeodeVerboseAccept = createConfigFile(FILE_NAME_GEODE_VERBOSE_ACCEPT);
+ this.configFileGeodeVerboseDeny = createConfigFile(FILE_NAME_GEODE_VERBOSE_DENY);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Configurator.shutdown();
+
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ if (this.beforeConfigFileProp != null) {
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.beforeConfigFileProp);
+ }
+ StatusLogger.getLogger().setLevel(this.beforeLevel);
+
+ LogService.reconfigure();
+ assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+
+ BasicAppender.clearInstance();
+
+ assertThat(this.systemErrRule.getLog()).isEmpty();
+ }
+
+ @Test
+ public void geodeVerboseShouldLogIfGeodeVerboseIsAccept() {
+ configureLogging(this.configFileGeodeVerboseAccept);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEODE_VERBOSE, msg);
+
+ assertThat(this.systemOutRule.getLog()).contains(msg);
+ }
+
+ @Test
+ public void geodeVerboseShouldNotLogIfGeodeVerboseIsDeny() {
+ configureLogging(this.configFileGeodeVerboseDeny);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEODE_VERBOSE, msg);
+
+ assertThat(this.systemOutRule.getLog()).doesNotContain(msg);
+ }
+
+ @Test
+ public void geodeVerboseShouldLogIfGemfireVerboseIsAccept() {
+ configureLogging(this.configFileGemfireVerboseAccept);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEODE_VERBOSE, msg);
+
+ assertThat(this.systemOutRule.getLog()).contains(msg);
+ }
+
+ @Test
+ public void geodeVerboseShouldNotLogIfGemfireVerboseIsDeny() {
+ configureLogging(this.configFileGemfireVerboseDeny);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEODE_VERBOSE, msg);
+
+ assertThat(this.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(this.configFileGeodeVerboseAccept);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
+
+ assertThat(this.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(this.configFileGeodeVerboseDeny);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
+
+ assertThat(this.systemOutRule.getLog()).contains(msg);
+ }
+
+ @Test
+ public void gemfireVerboseShouldLogIfGemfireVerboseIsAccept() {
+ configureLogging(this.configFileGemfireVerboseAccept);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
+
+ assertThat(this.systemOutRule.getLog()).contains(msg);
+ }
+
+ @Test
+ public void gemfireVerboseShouldNotLogIfGemfireVerboseIsDeny() {
+ configureLogging(this.configFileGemfireVerboseDeny);
+ Logger logger = LogService.getLogger();
+
+ String msg = this.testName.getMethodName();
+ logger.info(LogMarker.GEMFIRE_VERBOSE, msg);
+
+ assertThat(this.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(this.temporaryFolder.getRoot());
+ }
+
+ private void configureLogging(final File configFile) {
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, configFile.getAbsolutePath());
+ LogService.reconfigure();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
deleted file mode 100644
index ec9d257..0000000
--- a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
+++ /dev/null
@@ -1,112 +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.geode.internal.logging.log4j.custom.CustomConfiguration.*;
-import static org.assertj.core.api.Assertions.*;
-
-import java.io.File;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.config.ConfigurationFactory;
-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.apache.geode.internal.logging.LogService;
-import org.apache.geode.internal.logging.log4j.custom.BasicAppender;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-
-/**
- * Integration tests with custom log4j2 configuration.
- */
-@Category(IntegrationTest.class)
-public class LogMarkerJUnitTest {
-
- private String beforeConfigFileProp;
- private Level beforeLevel;
-
- @Rule
- public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
- @Rule
- public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- @Before
- public void setUp() throws Exception {
- Configurator.shutdown();
- BasicAppender.clearInstance();
-
- this.beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- this.beforeLevel = StatusLogger.getLogger().getLevel();
-
- final File customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
-
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, customConfigFile.getAbsolutePath());
- LogService.reconfigure();
- assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
- }
-
- @After
- public void tearDown() throws Exception {
- Configurator.shutdown();
-
- System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
- if (this.beforeConfigFileProp != null) {
- System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.beforeConfigFileProp);
- }
- StatusLogger.getLogger().setLevel(this.beforeLevel);
-
- LogService.reconfigure();
- assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
-
- BasicAppender.clearInstance();
-
- assertThat(this.systemErrRule.getLog()).isEmpty();
- }
-
- /**
- * Test to see that log messages for GEODE_VERBOSE are filtered, based on the log4j2-custom.xml configuration file
- */
- @Test
- public void testGeodeFilter() {
- Logger logger = LogService.getLogger();
- String msg = "verbose geode line";
- logger.error(LogMarker.GEODE_VERBOSE, msg);
- assertThat(systemOutRule.getLog()).contains("");
- }
-
- /**
- * Test to see that log messages for GEMFIRE_VERBOSE are not filtered, based on the log4j2-custom.xml configuration
- * file
- */
- @Test
- public void testGemfireFilter() {
- Logger logger = LogService.getLogger();
- String msg = "verbose gemfire line";
- logger.error(LogMarker.GEMFIRE_VERBOSE, msg);
- assertThat(systemOutRule.getLog()).contains(msg);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..1319b0e
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-accept.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="FATAL" 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=%tid] %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>
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..eb22649
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-gemfire_verbose-deny.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="FATAL" 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=%tid] %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>
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..73dab7c
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-accept.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="FATAL" 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=%tid] %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>
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/375c6c5b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..c0bfd1e
--- /dev/null
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/marker/log4j2-geode_verbose-deny.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="FATAL" 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=%tid] %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>
[2/3] incubator-geode git commit: GEODE-1902 - Add GEMFIRE_VERBOSE
LogMarker as alias of GEODE_VERBOSE for backwards compatibility
Posted by kl...@apache.org.
GEODE-1902 - Add GEMFIRE_VERBOSE LogMarker as alias of GEODE_VERBOSE for backwards compatibility
This closes #247
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c80cba2c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c80cba2c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c80cba2c
Branch: refs/heads/develop
Commit: c80cba2c81f55736121a0d12d7e01b3249c20bdd
Parents: 8929e93
Author: Kevin Duling <kd...@pivotal.io>
Authored: Mon Sep 26 16:10:34 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Oct 4 13:14:19 2016 -0700
----------------------------------------------------------------------
.../geode/internal/logging/LogService.java | 154 ++++++++++---------
.../internal/logging/log4j/Configurator.java | 69 ++++-----
.../geode/internal/logging/log4j/LogMarker.java | 78 ++++++----
.../logging/log4j/LogMarkerJUnitTest.java | 112 ++++++++++++++
.../logging/log4j/custom/log4j2-custom.xml | 52 ++++---
5 files changed, 294 insertions(+), 171 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c80cba2c/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java b/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
index 2c6eda3..405434d 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/LogService.java
@@ -30,6 +30,7 @@ import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.lookup.StrLookup;
import org.apache.logging.log4j.core.lookup.StrSubstitutor;
import org.apache.logging.log4j.status.StatusLogger;
+
import org.apache.geode.internal.logging.log4j.AppenderContext;
import org.apache.geode.internal.logging.log4j.ConfigLocator;
import org.apache.geode.internal.logging.log4j.Configurator;
@@ -42,75 +43,82 @@ import org.apache.geode.internal.logging.log4j.message.GemFireParameterizedMessa
*/
@SuppressWarnings("unused")
public class LogService extends LogManager {
+
// This is highest point in the hierarchy for all Geode logging
public static final String ROOT_LOGGER_NAME = "";
public static final String BASE_LOGGER_NAME = "org.apache.geode";
public static final String MAIN_LOGGER_NAME = "org.apache.geode";
public static final String SECURITY_LOGGER_NAME = "org.apache.geode.security";
-
- public static final String GEMFIRE_VERBOSE_FILTER = "{GEODE_VERBOSE}";
-
- protected static final String STDOUT = "STDOUT";
- private static final PropertyChangeListener propertyChangeListener = new PropertyChangeListenerImpl();
-
+ public static final String GEODE_VERBOSE_FILTER = "{GEODE_VERBOSE}";
+ public static final String GEMFIRE_VERBOSE_FILTER = "{GEMFIRE_VERBOSE}";
public static final String DEFAULT_CONFIG = "/log4j2.xml";
public static final String CLI_CONFIG = "/log4j2-cli.xml";
-
+ protected static final String STDOUT = "STDOUT";
+ private static final PropertyChangeListener propertyChangeListener = new PropertyChangeListenerImpl();
/**
* Name of variable that is set to "true" in log4j2.xml to indicate that it is the default geode config xml.
*/
private static final String GEMFIRE_DEFAULT_PROPERTY = "geode-default";
-
- /** Protected by static synchronization. Used for removal and adding stdout back in. */
+
+ /**
+ * Protected by static synchronization. Used for removal and adding stdout back in.
+ */
private static Appender stdoutAppender;
-
+
static {
init();
}
+
+ private LogService() {
+ // do not instantiate
+ }
+
private static void init() {
- LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext();
+ LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
+ .getContext();
context.removePropertyChangeListener(propertyChangeListener);
context.addPropertyChangeListener(propertyChangeListener);
context.reconfigure(); // propertyChangeListener invokes configureFastLoggerDelegating
configureLoggers(false, false);
}
-
+
public static void initialize() {
new LogService();
}
-
+
public static void reconfigure() {
init();
}
-
+
public static void configureLoggers(final boolean hasLogFile, final boolean hasSecurityLogFile) {
Configurator.getOrCreateLoggerConfig(BASE_LOGGER_NAME, true, false);
Configurator.getOrCreateLoggerConfig(MAIN_LOGGER_NAME, true, hasLogFile);
final boolean useMainLoggerForSecurity = !hasSecurityLogFile;
Configurator.getOrCreateLoggerConfig(SECURITY_LOGGER_NAME, useMainLoggerForSecurity, hasSecurityLogFile);
}
-
+
public static AppenderContext getAppenderContext() {
return new AppenderContext();
}
-
+
public static AppenderContext getAppenderContext(final String name) {
return new AppenderContext(name);
}
-
+
public static boolean isUsingGemFireDefaultConfig() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger)
- LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
-
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
+ .getContext()
+ .getConfiguration();
+
final StrSubstitutor sub = config.getStrSubstitutor();
final StrLookup resolver = sub.getVariableResolver();
-
+
final String value = resolver.lookup(GEMFIRE_DEFAULT_PROPERTY);
-
+
return "true".equals(value);
}
-
+
public static String getConfigInformation() {
return getConfiguration().getConfigurationSource().toString();
}
@@ -119,10 +127,9 @@ public class LogService extends LogManager {
* Finds a Log4j configuration file in the current directory. The names of
* the files to look for are the same as those that Log4j would look for on
* the classpath.
- *
* @return A File for the configuration file or null if one isn't found.
*/
- public static File findLog4jConfigInCurrentDir() {
+ public static File findLog4jConfigInCurrentDir() {
return ConfigLocator.findConfigInWorkingDirectory();
}
@@ -133,7 +140,7 @@ public class LogService extends LogManager {
public static Logger getLogger() {
return new FastLogger(LogManager.getLogger(getClassName(2), GemFireParameterizedMessageFactory.INSTANCE));
}
-
+
public static Logger getLogger(final String name) {
return new FastLogger(LogManager.getLogger(name, GemFireParameterizedMessageFactory.INSTANCE));
}
@@ -141,23 +148,24 @@ public class LogService extends LogManager {
/**
* Returns a LogWriterLogger that is decorated with the LogWriter and LogWriterI18n
* methods.
- *
+ * <p>
* This is the bridge to LogWriter and LogWriterI18n that we need to eventually
* stop using in phase 1. We will switch over from a shared LogWriterLogger instance
* to having every GemFire class own its own private static GemFireLogger
- *
* @return The LogWriterLogger for the calling class.
*/
- public static LogWriterLogger createLogWriterLogger(final String name, final String connectionName, final boolean isSecure) {
+ public static LogWriterLogger createLogWriterLogger(final String name,
+ final String connectionName,
+ final boolean isSecure) {
return LogWriterLogger.create(name, connectionName, isSecure);
}
-
+
/**
* Return the Log4j Level associated with the int level.
- *
- * @param intLevel
- * The int value of the Level to return.
+ * @param intLevel The int value of the Level to return.
+ *
* @return The Level.
+ *
* @throws java.lang.IllegalArgumentException if the Level int is not registered.
*/
public static Level toLevel(final int intLevel) {
@@ -172,8 +180,8 @@ public class LogService extends LogManager {
/**
* Gets the class name of the caller in the current stack at the given {@code depth}.
- *
* @param depth a 0-based index in the current stack.
+ *
* @return a class name
*/
public static String getClassName(final int depth) {
@@ -181,39 +189,33 @@ public class LogService extends LogManager {
}
public static Configuration getConfiguration() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger)
- LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
+ .getContext()
+ .getConfiguration();
return config;
}
-
+
public static void configureFastLoggerDelegating() {
- final Configuration config = ((org.apache.logging.log4j.core.Logger)
- LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext().getConfiguration();
-
- if (Configurator.hasContextWideFilter(config) ||
- Configurator.hasAppenderFilter(config) ||
- Configurator.hasDebugOrLower(config) ||
- Configurator.hasLoggerFilter(config) ||
- Configurator.hasAppenderRefFilter(config)) {
+ final Configuration config = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(ROOT_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE))
+ .getContext()
+ .getConfiguration();
+
+ if (Configurator.hasContextWideFilter(config) || Configurator.hasAppenderFilter(config) || Configurator.hasDebugOrLower(config) || Configurator
+ .hasLoggerFilter(config) || Configurator.hasAppenderRefFilter(config)) {
FastLogger.setDelegating(true);
} else {
FastLogger.setDelegating(false);
}
}
-
- private static class PropertyChangeListenerImpl implements PropertyChangeListener {
- @SuppressWarnings("synthetic-access")
- @Override
- public void propertyChange(final PropertyChangeEvent evt) {
- StatusLogger.getLogger().debug("LogService responding to a property change event. Property name is {}.",
- evt.getPropertyName());
-
- if (evt.getPropertyName().equals(LoggerContext.PROPERTY_CONFIG)) {
- configureFastLoggerDelegating();
- }
- }
+
+ public static void setSecurityLogLevel(Level level) {
+ Configurator.setLevel(SECURITY_LOGGER_NAME, level);
}
-
+
+ public static Level getBaseLogLevel() {
+ return Configurator.getLevel(BASE_LOGGER_NAME);
+ }
+
public static void setBaseLogLevel(Level level) {
if (isUsingGemFireDefaultConfig()) {
Configurator.setLevel(ROOT_LOGGER_NAME, level);
@@ -221,23 +223,15 @@ public class LogService extends LogManager {
Configurator.setLevel(BASE_LOGGER_NAME, level);
Configurator.setLevel(MAIN_LOGGER_NAME, level);
}
-
- public static void setSecurityLogLevel(Level level) {
- Configurator.setLevel(SECURITY_LOGGER_NAME, level);
- }
-
- public static Level getBaseLogLevel() {
- return Configurator.getLevel(BASE_LOGGER_NAME);
- }
-
+
public static LoggerConfig getRootLoggerConfig() {
return Configurator.getLoggerConfig(LogManager.getRootLogger().getName());
}
-
+
/**
* Removes STDOUT ConsoleAppender from ROOT logger. Only called when using
* the log4j2-default.xml configuration. This is done when creating the
- * LogWriterAppender for log-file. The Appender instance is stored in
+ * LogWriterAppender for log-file. The Appender instance is stored in
* stdoutAppender so it can be restored later using restoreConsoleAppender.
*/
public static synchronized void removeConsoleAppender() {
@@ -250,11 +244,11 @@ public class LogService extends LogManager {
appenderContext.getLoggerContext().updateLoggers();
}
}
-
+
/**
* Restores STDOUT ConsoleAppender to ROOT logger. Only called when using
- * the log4j2-default.xml configuration. This is done when the
- * LogWriterAppender for log-file is destroyed. The Appender instance stored
+ * the log4j2-default.xml configuration. This is done when the
+ * LogWriterAppender for log-file is destroyed. The Appender instance stored
* in stdoutAppender is used.
*/
public static synchronized void restoreConsoleAppender() {
@@ -269,8 +263,18 @@ public class LogService extends LogManager {
appenderContext.getLoggerContext().updateLoggers();
}
}
-
- private LogService() {
- // do not instantiate
+
+ private static class PropertyChangeListenerImpl implements PropertyChangeListener {
+
+ @SuppressWarnings("synthetic-access")
+ @Override
+ public void propertyChange(final PropertyChangeEvent evt) {
+ StatusLogger.getLogger()
+ .debug("LogService responding to a property change event. Property name is {}.", evt.getPropertyName());
+
+ if (evt.getPropertyName().equals(LoggerContext.PROPERTY_CONFIG)) {
+ configureFastLoggerDelegating();
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c80cba2c/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
index 3f769c0..fb942b8 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/Configurator.java
@@ -26,7 +26,6 @@ import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.AppenderRef;
import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilterable;
@@ -34,7 +33,7 @@ import org.apache.logging.log4j.core.filter.AbstractFilterable;
import org.apache.geode.internal.logging.LogService;
/**
- * Utility methods to programmatically alter the configuration of Log4J2. Used
+ * Utility methods to programmatically alter the configuration of Log4J2. Used
* by LogService and tests.
*/
public class Configurator {
@@ -44,34 +43,34 @@ public class Configurator {
context.updateLoggers();
//context.reconfigure();
}*/
-
+
public static void shutdown() {
//LoggerContext context = (LoggerContext)LogManager.getContext(false);
- final LoggerContext context = ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).getContext();
+ final LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).getContext();
context.stop();
org.apache.logging.log4j.core.config.Configurator.shutdown(context);
}
-
+
public static void setLevel(String name, Level level) {
- LoggerContext context = (LoggerContext)LogManager.getContext(false);
+ LoggerContext context = (LoggerContext) LogManager.getContext(false);
LoggerConfig logConfig = getLoggerConfig(name);
logConfig.setLevel(level);
context.updateLoggers();
-
+
if (level.isLessSpecificThan(Level.DEBUG)) {
LogService.configureFastLoggerDelegating();
}
}
-
+
public static Level getLevel(String name) {
LoggerConfig logConfig = getOrCreateLoggerConfig(name);
return logConfig.getLevel();
}
-
+
public static LoggerConfig getOrCreateLoggerConfig(String name) {
- LoggerContext context = (LoggerContext)LogManager.getContext(false);
+ LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
boolean update = false;
@@ -79,15 +78,9 @@ public class Configurator {
List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
Map<Property, Boolean> properties = logConfig.getProperties();
Set<Property> props = properties == null ? null : properties.keySet();
- logConfig = LoggerConfig.createLogger(
- String.valueOf(logConfig.isAdditive()),
- logConfig.getLevel(),
- name,
- String.valueOf(logConfig.isIncludeLocation()),
- appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]),
- props == null ? null : props.toArray(new Property[props.size()]),
- config,
- null);
+ logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()), logConfig.getLevel(), name, String.valueOf(logConfig
+ .isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props
+ .toArray(new Property[props.size()]), config, null);
config.addLogger(name, logConfig);
update = true;
}
@@ -98,7 +91,7 @@ public class Configurator {
}
public static LoggerConfig getOrCreateLoggerConfig(String name, boolean additive, boolean forceAdditivity) {
- LoggerContext context = (LoggerContext)LogManager.getContext(false);
+ LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
boolean update = false;
@@ -106,15 +99,9 @@ public class Configurator {
List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
Map<Property, Boolean> properties = logConfig.getProperties();
Set<Property> props = properties == null ? null : properties.keySet();
- logConfig = LoggerConfig.createLogger(
- String.valueOf(additive),
- logConfig.getLevel(),
- name,
- String.valueOf(logConfig.isIncludeLocation()),
- appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]),
- props == null ? null : props.toArray(new Property[props.size()]),
- config,
- null);
+ logConfig = LoggerConfig.createLogger(String.valueOf(additive), logConfig.getLevel(), name, String.valueOf(logConfig
+ .isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props
+ .toArray(new Property[props.size()]), config, null);
config.addLogger(name, logConfig);
update = true;
}
@@ -127,9 +114,9 @@ public class Configurator {
}
return logConfig;
}
-
+
public static LoggerConfig getLoggerConfig(final String name) {
- LoggerContext context = (LoggerContext)LogManager.getContext(false);
+ LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
if (!logConfig.getName().equals(name)) {
@@ -141,11 +128,11 @@ public class Configurator {
public static boolean hasContextWideFilter(final Configuration config) {
return config.hasFilter();
}
-
+
public static String getConfigurationSourceLocation(final Configuration config) {
return config.getConfigurationSource().getLocation();
}
-
+
public static boolean hasAppenderFilter(final Configuration config) {
for (Appender appender : config.getAppenders().values()) {
if (appender instanceof AbstractFilterable) {
@@ -156,7 +143,7 @@ public class Configurator {
}
return false;
}
-
+
public static boolean hasDebugOrLower(final Configuration config) {
for (LoggerConfig loggerConfig : config.getLoggers().values()) {
boolean isDebugOrLower = loggerConfig.getLevel().isLessSpecificThan(Level.DEBUG);
@@ -166,14 +153,16 @@ public class Configurator {
}
return false;
}
-
+
public static boolean hasLoggerFilter(final Configuration config) {
for (LoggerConfig loggerConfig : config.getLoggers().values()) {
boolean isRoot = loggerConfig.getName().equals("");
boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
boolean hasFilter = loggerConfig.hasFilter();
- boolean isGemFireVerboseFilter = hasFilter && LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString());
-
+ boolean isGemFireVerboseFilter = hasFilter && (LogService.GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter()
+ .toString()) || LogService.GEMFIRE_VERBOSE_FILTER
+ .equals(loggerConfig.getFilter().toString()));
+
if (isRoot || isGemFire) {
// check for Logger Filter
if (hasFilter && !isGemFireVerboseFilter) {
@@ -183,14 +172,12 @@ public class Configurator {
}
return false;
}
-
+
public static boolean hasAppenderRefFilter(final Configuration config) {
for (LoggerConfig loggerConfig : config.getLoggers().values()) {
boolean isRoot = loggerConfig.getName().equals("");
boolean isGemFire = loggerConfig.getName().startsWith(LogService.BASE_LOGGER_NAME);
- boolean hasFilter = loggerConfig.hasFilter();
- boolean isGemFireVerboseFilter = hasFilter && LogService.GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString());
-
+
if (isRoot || isGemFire) {
// check for AppenderRef Filter
for (AppenderRef appenderRef : loggerConfig.getAppenderRefs()) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c80cba2c/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
index 3c1eff8..42b5b17 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/logging/log4j/LogMarker.java
@@ -24,75 +24,93 @@ import org.apache.logging.log4j.MarkerManager;
import org.apache.geode.DataSerializable;
public interface LogMarker {
+
/**
* GEODE_VERBOSE is a parent to all other markers so that they can all be turned off with<br>
* <MarkerFilter marker="GEODE_VERBOSE" onMatch="DENY" onMismatch="NEUTRAL"/>
+ * <p>
+ * GEMFIRE_VERBOSE will be deprecated in the near future
*/
- public static final Marker GEODE_VERBOSE = MarkerManager.getMarker("GEODE_VERBOSE");
-
+ public static final Marker GEMFIRE_VERBOSE = MarkerManager.getMarker("GEMFIRE_VERBOSE");
+ public static final Marker GEODE_VERBOSE = MarkerManager.getMarker("GEODE_VERBOSE").setParents(GEMFIRE_VERBOSE);
+
public static final Marker BRIDGE_SERVER = MarkerManager.getMarker("BRIDGE_SERVER").addParents(GEODE_VERBOSE);
public static final Marker DLS = MarkerManager.getMarker("DLS").addParents(GEODE_VERBOSE);
-
+
public static final Marker PERSIST = MarkerManager.getMarker("PERSIST").addParents(GEODE_VERBOSE);
public static final Marker PERSIST_VIEW = MarkerManager.getMarker("PERSIST_VIEW").addParents(PERSIST);
public static final Marker PERSIST_ADVISOR = MarkerManager.getMarker("PERSIST_ADVISOR").addParents(PERSIST);
public static final Marker PERSIST_RECOVERY = MarkerManager.getMarker("PERSIST_RECOVERY").addParents(PERSIST);
public static final Marker PERSIST_WRITES = MarkerManager.getMarker("PERSIST_WRITES").addParents(PERSIST);
-
+
public static final Marker TOMBSTONE = MarkerManager.getMarker("TOMBSTONE").addParents(GEODE_VERBOSE);
public static final Marker TOMBSTONE_COUNT = MarkerManager.getMarker("TOMBSTONE_COUNT").addParents(TOMBSTONE);
-
+
public static final Marker LRU = MarkerManager.getMarker("LRU").addParents(GEODE_VERBOSE);
- public static final Marker LRU_TOMBSTONE_COUNT = MarkerManager.getMarker("LRU_TOMBSTONE_COUNT").addParents(LRU, TOMBSTONE_COUNT);
+ public static final Marker LRU_TOMBSTONE_COUNT = MarkerManager.getMarker("LRU_TOMBSTONE_COUNT")
+ .addParents(LRU, TOMBSTONE_COUNT);
public static final Marker LRU_CLOCK = MarkerManager.getMarker("LRU_CLOCK").addParents(LRU);
-
+
public static final Marker RVV = MarkerManager.getMarker("RVV").addParents(GEODE_VERBOSE);
- public static final Marker VERSION_TAG = MarkerManager.getMarker("VERSION_TAG").addParents(GEODE_VERBOSE); // gemfire.VersionTag.DEBUG
- public static final Marker VERSIONED_OBJECT_LIST = MarkerManager.getMarker("VERSIONED_OBJECT_LIST").addParents(GEODE_VERBOSE); // gemfire.VersionedObjectList.DEBUG
+ public static final Marker VERSION_TAG = MarkerManager.getMarker("VERSION_TAG")
+ .addParents(GEODE_VERBOSE); // gemfire.VersionTag.DEBUG
+ public static final Marker VERSIONED_OBJECT_LIST = MarkerManager.getMarker("VERSIONED_OBJECT_LIST")
+ .addParents(GEODE_VERBOSE); // gemfire.VersionedObjectList.DEBUG
// cache.tier.sockets
- public static final Marker OBJECT_PART_LIST = MarkerManager.getMarker("OBJECT_PART_LIST").addParents(GEODE_VERBOSE); // gemfire.ObjectPartList.DEBUG
-
- public static final Marker SERIALIZER = MarkerManager.getMarker("SERIALIZER").addParents(GEODE_VERBOSE); // DataSerializer.DEBUG
- /** If the <code>"DataSerializer.DUMP_SERIALIZED"</code> system
+ public static final Marker OBJECT_PART_LIST = MarkerManager.getMarker("OBJECT_PART_LIST")
+ .addParents(GEODE_VERBOSE); // gemfire.ObjectPartList.DEBUG
+
+ public static final Marker SERIALIZER = MarkerManager.getMarker("SERIALIZER")
+ .addParents(GEODE_VERBOSE); // DataSerializer.DEBUG
+ /**
+ * If the <code>"DataSerializer.DUMP_SERIALIZED"</code> system
* property is set, the class names of the objects that are
* serialized by {@link org.apache.geode.DataSerializer#writeObject(Object, DataOutput)} using standard Java
* serialization are logged to {@linkplain System#out standard out}.
* This aids in determining which classes should implement {@link
* DataSerializable} (or should be special cased by a custom
- * <code>DataSerializer</code>). */
- public static final Marker DUMP_SERIALIZED = MarkerManager.getMarker("DUMP_SERIALIZED").addParents(SERIALIZER); // DataSerializer.DUMP_SERIALIZED
- public static final Marker TRACE_SERIALIZABLE = MarkerManager.getMarker("TRACE_SERIALIZABLE").addParents(SERIALIZER); // DataSerializer.TRACE_SERIALIZABLE
- public static final Marker DEBUG_DSFID = MarkerManager.getMarker("DEBUG_DSFID").addParents(SERIALIZER); // DataSerializer.DEBUG_DSFID
-
+ * <code>DataSerializer</code>).
+ */
+ public static final Marker DUMP_SERIALIZED = MarkerManager.getMarker("DUMP_SERIALIZED")
+ .addParents(SERIALIZER); // DataSerializer.DUMP_SERIALIZED
+ public static final Marker TRACE_SERIALIZABLE = MarkerManager.getMarker("TRACE_SERIALIZABLE")
+ .addParents(SERIALIZER); // DataSerializer.TRACE_SERIALIZABLE
+ public static final Marker DEBUG_DSFID = MarkerManager.getMarker("DEBUG_DSFID")
+ .addParents(SERIALIZER); // DataSerializer.DEBUG_DSFID
+
public static final Marker STATISTICS = MarkerManager.getMarker("STATISTICS").addParents(GEODE_VERBOSE);
public static final Marker STATE_FLUSH_OP = MarkerManager.getMarker("STATE_FLUSH_OP").addParents(GEODE_VERBOSE);
-
+
public static final Marker DISTRIBUTION = MarkerManager.getMarker("DISTRIBUTION").addParents(GEODE_VERBOSE);
- public static final Marker DISTRIBUTION_STATE_FLUSH_OP = MarkerManager.getMarker("DISTRIBUTION_STATE_FLUSH_OP").addParents(DISTRIBUTION, STATE_FLUSH_OP);
- public static final Marker DISTRIBUTION_BRIDGE_SERVER = MarkerManager.getMarker("DISTRIBUTION_BRIDGE_SERVER").addParents(DISTRIBUTION, BRIDGE_SERVER);
- public static final Marker DISTRIBUTION_VIEWS = MarkerManager.getMarker("DISTRIBUTION_VIEWS").addParents(DISTRIBUTION);
+ public static final Marker DISTRIBUTION_STATE_FLUSH_OP = MarkerManager.getMarker("DISTRIBUTION_STATE_FLUSH_OP")
+ .addParents(DISTRIBUTION, STATE_FLUSH_OP);
+ public static final Marker DISTRIBUTION_BRIDGE_SERVER = MarkerManager.getMarker("DISTRIBUTION_BRIDGE_SERVER")
+ .addParents(DISTRIBUTION, BRIDGE_SERVER);
+ public static final Marker DISTRIBUTION_VIEWS = MarkerManager.getMarker("DISTRIBUTION_VIEWS")
+ .addParents(DISTRIBUTION);
public static final Marker DM = MarkerManager.getMarker("DM").addParents(DISTRIBUTION);
public static final Marker DM_BRIDGE_SERVER = MarkerManager.getMarker("DM_BRIDGE").addParents(BRIDGE_SERVER, DM);
public static final Marker DA = MarkerManager.getMarker("DA").addParents(DISTRIBUTION);
public static final Marker GII = MarkerManager.getMarker("GII").addParents(GEODE_VERBOSE);
public static final Marker GII_VERSIONED_ENTRY = MarkerManager.getMarker("GII_VERSION_ENTRY").addParents(GII);
-
+
public static final Marker JGROUPS = MarkerManager.getMarker("JGROUPS").addParents(GEODE_VERBOSE);
-
+
public static final Marker QA = MarkerManager.getMarker("QA").addParents(GEODE_VERBOSE);
-
+
public static final Marker P2P = MarkerManager.getMarker("P2P").addParents(GEODE_VERBOSE);
-
+
public static final Marker CONFIG = MarkerManager.getMarker("CONFIG");
-
+
public static final Marker PERSISTENCE = MarkerManager.getMarker("PERSISTENCE").addParents(GEODE_VERBOSE);
public static final Marker DISK_STORE_MONITOR = MarkerManager.getMarker("DISK_STORE_MONITOR").addParents(PERSISTENCE);
public static final Marker SOPLOG = MarkerManager.getMarker("SOPLOG").addParents(PERSISTENCE);
-
+
public static final Marker MANAGED_ENTITY = MarkerManager.getMarker("MANAGED_ENTITY").addParents(GEODE_VERBOSE);
-
+
public static final Marker CACHE_XML = MarkerManager.getMarker("CACHE_XML").addParents(GEODE_VERBOSE);
- public static final Marker CACHE_XML_PARSER = MarkerManager.getMarker("CACHE_XML_PARSER").addParents(GEODE_VERBOSE, CACHE_XML);
+ public static final Marker CACHE_XML_PARSER = MarkerManager.getMarker("CACHE_XML_PARSER")
+ .addParents(GEODE_VERBOSE, CACHE_XML);
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c80cba2c/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
new file mode 100644
index 0000000..3077180
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/logging/log4j/LogMarkerJUnitTest.java
@@ -0,0 +1,112 @@
+/*
+ * 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.internal.logging.log4j.custom.CustomConfiguration.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.File;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.config.ConfigurationFactory;
+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.apache.geode.internal.logging.LogService;
+import org.apache.geode.internal.logging.log4j.custom.BasicAppender;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+
+/**
+ * Integration tests with custom log4j2 configuration.
+ */
+@Category(IntegrationTest.class)
+public class LogMarkerJUnitTest {
+
+ @Rule
+ public SystemErrRule systemErrRule = new SystemErrRule().enableLog();
+ @Rule
+ public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ private String beforeConfigFileProp;
+ private Level beforeLevel;
+
+ @Before
+ public void setUp() throws Exception {
+ Configurator.shutdown();
+ BasicAppender.clearInstance();
+
+ this.beforeConfigFileProp = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ this.beforeLevel = StatusLogger.getLogger().getLevel();
+
+ final File customConfigFile = createConfigFileIn(this.temporaryFolder.getRoot());
+
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, customConfigFile.getAbsolutePath());
+ LogService.reconfigure();
+ assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isFalse();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Configurator.shutdown();
+
+ System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+ if (this.beforeConfigFileProp != null) {
+ System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, this.beforeConfigFileProp);
+ }
+ StatusLogger.getLogger().setLevel(this.beforeLevel);
+
+ LogService.reconfigure();
+ assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
+
+ BasicAppender.clearInstance();
+
+ assertThat(this.systemErrRule.getLog()).isEmpty();
+ }
+
+ /**
+ * Test to see that log messages for GEODE_VERBOSE are filtered, based on the log4j2-custom.xml configuration file
+ */
+ @Test
+ public void testGeodeFilter() {
+ Logger logger = LogService.getLogger();
+ String msg = "verbose geode line";
+ logger.error(LogMarker.GEODE_VERBOSE, msg);
+ assertThat(systemOutRule.getLog()).contains("");
+ }
+
+ /**
+ * Test to see that log messages for GEMFIRE_VERBOSE are not filtered, based on the log4j2-custom.xml configuration
+ * file
+ */
+ @Test
+ public void testGemfireFilter() {
+ Logger logger = LogService.getLogger();
+ String msg = "verbose gemfire line";
+ logger.error(LogMarker.GEMFIRE_VERBOSE, msg);
+ assertThat(systemOutRule.getLog()).contains(msg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c80cba2c/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
index 8ab555f..4567ccc 100644
--- a/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
+++ b/geode-core/src/test/resources/org/apache/geode/internal/logging/log4j/custom/log4j2-custom.xml
@@ -1,28 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="FATAL" shutdownHook="disable" packages="org.apache.geode.internal.logging.log4j.custom">
- <Properties>
- <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z} message=%message%nthrowable=%throwable%n</Property>
- </Properties>
- <Appenders>
- <Console name="STDOUT" target="SYSTEM_OUT">
- <PatternLayout pattern="${custom-pattern}"/>
- </Console>
- <Basic name="CUSTOM">
- <PatternLayout pattern="${custom-pattern}"/>
- </Basic>
- </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="NEUTRAL"/>
- </filters>
- </Logger>
- <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
- <Logger name="org.jgroups" level="FATAL" additivity="true"/>
- <Root level="INFO">
- <AppenderRef ref="CUSTOM"/>
- <AppenderRef ref="STDOUT"/>
- </Root>
- </Loggers>
+ <Properties>
+ <Property name="custom-pattern">CUSTOM: level=%level time=%date{yyyy/MM/dd HH:mm:ss.SSS z}
+ message=%message%nthrowable=%throwable%n
+ </Property>
+ </Properties>
+ <Appenders>
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Console>
+ <Basic name="CUSTOM">
+ <PatternLayout pattern="${custom-pattern}"/>
+ </Basic>
+ </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="NEUTRAL"/>
+ </filters>
+ </Logger>
+ <Logger name="org.apache.geode.internal.logging.log4j.custom" level="DEBUG" additivity="true"/>
+ <Logger name="org.jgroups" level="FATAL" additivity="true"/>
+ <Root level="INFO">
+ <AppenderRef ref="CUSTOM"/>
+ <AppenderRef ref="STDOUT"/>
+ </Root>
+ </Loggers>
</Configuration>