[
https://issues.apache.org/jira/browse/LOG4J2-1015?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14546531#comment-14546531
]
Gary Gregory commented on LOG4J2-1015:
--------------------------------------
How about this then:
{code:java}
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
index b0348e8..e257a23 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/Interpolator.java
@@ -85,6 +85,7 @@
lookups.put("sys", new SystemPropertiesLookup());
lookups.put("env", new EnvironmentLookup());
lookups.put("main", MapLookup.MAIN_SINGLETON);
+ lookups.put("marker", new MarkerLookup());
lookups.put("java", new JavaLookup());
// JNDI
try {
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MarkerLookup.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MarkerLookup.java
new file mode 100644
index 0000000..88d2c95
--- /dev/null
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MarkerLookup.java
@@ -0,0 +1,46 @@
+/*
+ * 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.lookup;
+
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.MarkerManager;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+
+/**
+ * Looks up markers.
+ *
+ * @since 2.4
+ */
+@Plugin(name = "marker", category = StrLookup.CATEGORY)
+public class MarkerLookup extends AbstractLookup {
+
+ static final String MARKER = "marker";
+
+ @Override
+ public String lookup(final LogEvent event, final String key) {
+ final Marker marker = event.getMarker();
+ return marker == null ? null : marker.getName();
+ }
+
+ @Override
+ public String lookup(final String key) {
+ return MarkerManager.exists(key) ? key : null;
+ }
+
+}
diff --git
a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
new file mode 100644
index 0000000..c9f195c
--- /dev/null
+++
b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MarkerLookupTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.lookup;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.apache.logging.log4j.MarkerManager;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class MarkerLookupTest {
+
+ @Test
+ public void testLookupNonExistant() {
+ final StrLookup lookup = new MarkerLookup();
+ final String value = lookup.lookup("NONE");
+ assertNull(value);
+ }
+
+ @Test
+ public void testLookupExistant() {
+ final StrLookup lookup = new MarkerLookup();
+ final String name = "MarkerLookupTest";
+ final String value =
lookup.lookup(MarkerManager.getMarker(name).getName());
+ assertEquals(name, value);
+ }
+
+}
{code}
> Add a way to route messages based on the %marker in Layout for RoutingAppender
> ------------------------------------------------------------------------------
>
> Key: LOG4J2-1015
> URL: https://issues.apache.org/jira/browse/LOG4J2-1015
> Project: Log4j 2
> Issue Type: New Feature
> Components: Appenders
> Affects Versions: 2.2
> Reporter: Daniel Marcotte
>
> Hi,
> It seems there's no way to route messages based on the Marker in the
> RoutingAppender. The "%marker" is not part of the Layout. When using SLF4J,
> since it's a core feature of the facade, this would help greatly if it was
> possible to route messages based on the Marker.
> Main StackOverFlow question (answered) :
> http://stackoverflow.com/questions/30111754/log4j2-is-there-a-way-to-route-logs-based-on-marker-with-the-routingappender
> Workaround StackOverFlow question (answered) :
> http://stackoverflow.com/questions/30247323/how-to-create-custom-rewritepolicy-in-log4j2
> Thank you
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]