LOG4J2-1447 ContextDataFactory

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c6a18561
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c6a18561
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c6a18561

Branch: 
refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: c6a1856192e161e436762cafd9790336e194981b
Parents: e2c2137
Author: rpopma <[email protected]>
Authored: Wed Jul 27 01:08:39 2016 +0900
Committer: rpopma <[email protected]>
Committed: Wed Jul 27 01:08:39 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/ContextDataFactory.java     | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c6a18561/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataFactory.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataFactory.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataFactory.java
new file mode 100644
index 0000000..8d82e08
--- /dev/null
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ContextDataFactory.java
@@ -0,0 +1,44 @@
+/*
+ * 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.logging.log4j.core.impl;
+
+import org.apache.logging.log4j.util.PropertiesUtil;
+
+/**
+ * Factory for creating MutableContextData instances.
+ * <p>
+ * By default returns {@code ArrayContextData} objects. Can be configured by 
setting system property
+ * {@code "log4j2.ContextData"} to the fully qualified class name of a class 
implementing the
+ * {@code MutableContextData} interface. The class must have a public default 
constructor.
+ * </p>
+ *
+ * @see ArrayContextData
+ * @since 2.7
+ */
+public class ContextDataFactory {
+
+    @SuppressWarnings("unchecked")
+    public static MutableContextData getContextData() {
+        final String CLASS = 
PropertiesUtil.getProperties().getStringProperty("log4j2.ContextData",
+                ArrayContextData.class.getName());
+        try {
+            return (MutableContextData) Class.forName(CLASS).newInstance();
+        } catch (final Exception any) {
+            return new ArrayContextData();
+        }
+    }
+}

Reply via email to