You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/08/22 15:21:33 UTC
logging-log4j2 git commit: LOG4J2-1010 ContextMapLookup should get
context data from the configured ContextDataInjector,
not hard-coded from ThreadContext
Repository: logging-log4j2
Updated Branches:
refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure 2aeeb744b -> 88d2066d9
LOG4J2-1010 ContextMapLookup should get context data from the configured ContextDataInjector, not hard-coded from ThreadContext
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/88d2066d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/88d2066d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/88d2066d
Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 88d2066d9001d4862df69871fed669d3652613f5
Parents: 2aeeb74
Author: rpopma <rp...@apache.org>
Authored: Tue Aug 23 00:21:29 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Aug 23 00:21:29 2016 +0900
----------------------------------------------------------------------
.../log4j/core/lookup/ContextMapLookup.java | 22 ++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/88d2066d/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ContextMapLookup.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ContextMapLookup.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ContextMapLookup.java
index b7655a6..57818bc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ContextMapLookup.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/ContextMapLookup.java
@@ -17,15 +17,24 @@
package org.apache.logging.log4j.core.lookup;
import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.ContextData;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.impl.ContextDataFactory;
+import org.apache.logging.log4j.core.impl.ContextDataInjector;
+import org.apache.logging.log4j.core.impl.ContextDataInjectorFactory;
+import org.apache.logging.log4j.core.impl.MutableContextData;
/**
- * Looks up keys from {@link ThreadContext} objects..
+ * Looks up keys from the context. By default this is the {@link ThreadContext}, but users may
+ * {@linkplain ContextDataInjectorFactory configure} a custom {@link ContextDataInjector} which obtains context data
+ * from some other source.
*/
@Plugin(name = "ctx", category = StrLookup.CATEGORY)
public class ContextMapLookup implements StrLookup {
+ private final ContextDataInjector injector = ContextDataInjectorFactory.createInjector();
+
/**
* Looks up the value from the ThreadContext Map.
* @param key the key to be looked up, may be null
@@ -33,7 +42,16 @@ public class ContextMapLookup implements StrLookup {
*/
@Override
public String lookup(final String key) {
- return ThreadContext.get(key);
+ return currentContextData().getValue(key);
+ }
+
+ private ContextData currentContextData() {
+ return injector.injectContextData(null, reusableInstance());
+ }
+
+ private MutableContextData reusableInstance() {
+ // TODO if (Constants.ENABLE_THREADLOCALS) return thread-local instance
+ return ContextDataFactory.createContextData(); // creates temporary object
}
/**