logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1190159 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-api/src/main/java/org/apache/logging/log4j/message/ log4j2-core/src/main/java/org/apache/logging/log4j/core/ log4j2-core/src/main/java/org/apache/logging/log4j/cor...
Date Fri, 28 Oct 2011 04:55:36 GMT
Author: rgoers
Date: Fri Oct 28 04:55:34 2011
New Revision: 1190159

URL: http://svn.apache.org/viewvc?rev=1190159&view=rev
Log:
Add RewritePolicy, RewriteAppender, MapFilter, MapRewritePolicy

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java
      - copied, changed from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewritePolicy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java
      - copied, changed from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java
      - copied, changed from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/KeyValuePair.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java
      - copied, changed from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MapFilterTest.java
      - copied, changed from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-rewrite.xml
      - copied, changed from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.xml
Removed:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/KeyValuePair.java
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilterTest.java

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MapMessage.java Fri Oct 28 04:55:34 2011
@@ -191,6 +191,10 @@ public class MapMessage implements Forma
         }
     }
 
+    public MapMessage newInstance(Map<String, String> map) {
+        return new MapMessage(map);
+    }
+
     public String toString() {
         return asString();
     }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/StructuredDataMessage.java Fri Oct 28 04:55:34 2011
@@ -71,6 +71,19 @@ public class StructuredDataMessage exten
     }
 
     /**
+     * Constructor based on a StructuredDataMessage.
+     * @param msg The StructuredDataMessage.
+     * @param map The StructuredData map.
+     */
+    private StructuredDataMessage(StructuredDataMessage msg, Map<String, String> map) {
+        super(map);
+        this.id = msg.id;
+        this.message = msg.message;
+        this.type = msg.type;
+    }
+
+
+    /**
      * Basic constructor.
      */
     protected StructuredDataMessage() {
@@ -213,6 +226,11 @@ public class StructuredDataMessage exten
         return asString(null);
     }
 
+
+    public MapMessage newInstance(Map<String, String> map) {
+        return new StructuredDataMessage(this, map);
+    }
+
     public boolean equals(Object o) {
         if (this == o) {
             return true;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LogEvent.java Fri Oct 28 04:55:34 2011
@@ -102,4 +102,10 @@ public interface LogEvent extends Serial
      */
     Stack<String> getContextStack();
 
+    /**
+     * Returns the fully qualified class name of the caller of the logging api.
+     * @return The fully qualified class name of the caller.
+     */
+    String getFQCN();
+
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/flume/FlumeEvent.java Fri Oct 28 04:55:34 2011
@@ -165,6 +165,10 @@ class FlumeEvent extends EventBaseImpl i
         return Priority.INFO;
     }
 
+    public String getFQCN() {
+        return event.getFQCN();
+    }
+
     @Override
     public long getTimestamp() {
         return event.getMillis();

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java?rev=1190159&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicy.java Fri Oct 28 04:55:34 2011
@@ -0,0 +1,135 @@
+/*
+ * 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.appender.rewrite;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginAttr;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+@Plugin(name = "MapRewritePolicy", type = "Core", elementType = "rewritePolicy", printObject = true)
+public class MapRewritePolicy implements RewritePolicy {
+
+    protected final static Logger logger = StatusLogger.getLogger();
+
+    private final Map<String, String> map;
+
+    private final Mode mode;
+
+    private MapRewritePolicy(Map<String, String> map, Mode mode) {
+        this.map = map;
+        this.mode = mode;
+    }
+
+    public LogEvent rewrite(LogEvent source) {
+        Message msg = source.getMessage();
+        if (msg == null || !(msg instanceof MapMessage)) {
+            return source;
+        }
+
+        Map<String, String> newMap = new HashMap<String, String>(((MapMessage) msg).getData());
+        switch (mode) {
+            case Add: {
+                newMap.putAll(map);
+                break;
+            }
+            default: {
+                for (Map.Entry<String, String> entry : map.entrySet()) {
+                    if (newMap.containsKey(entry.getKey())) {
+                        newMap.put(entry.getKey(), entry.getValue());
+                    }
+                }
+            }
+        }
+        newMap.putAll(map);
+        MapMessage message = ((MapMessage) msg).newInstance(newMap);
+        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
+            message, source.getThrown(), source.getContextMap(), source.getContextStack(), source.getThreadName(),
+            source.getSource(), source.getMillis());
+    }
+
+    public enum Mode {
+        Add, Update
+    }
+
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("mode=").append(mode);
+        sb.append(" {");
+        boolean first = true;
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            if (!first) {
+                sb.append(", ");
+            }
+            sb.append(entry.getKey()).append("=").append(entry.getValue());
+            first = false;
+        }
+        sb.append("}");
+        return sb.toString();
+    }
+
+    @PluginFactory
+    public static MapRewritePolicy createPolicy(@PluginAttr("mode") String mode,
+                                                @PluginElement("KeyValuePair") KeyValuePair[] pairs) {
+        Mode op;
+        if (mode == null) {
+            op = Mode.Add;
+        } else {
+            op = Mode.valueOf(mode);
+            if (op == null) {
+                logger.error("Undefined mode " + mode);
+                return null;
+            }
+        }
+        if (pairs == null || pairs.length == 0) {
+            logger.error("keys and values must be specified for the MapRewritePolicy");
+            return null;
+        }
+        Map<String, String> map = new HashMap<String, String>();
+        for (KeyValuePair pair : pairs) {
+            String key = pair.getKey();
+            if (key == null) {
+                logger.error("A null key is not valid in MapRewritePolicy");
+                continue;
+            }
+            String value = pair.getValue();
+            if (value == null) {
+                logger.error("A null value for key " + key + " is not allowed in MapRewritePolicy");
+                continue;
+            }
+            map.put(pair.getKey(), pair.getValue());
+        }
+        if (map.size() == 0) {
+            logger.error("MapRewritePolicy is not configured with any valid key value pairs");
+            return null;
+        }
+        return new MapRewritePolicy(map, op);
+    }
+}

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java (from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java&r1=1188557&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppender.java Fri Oct 28 04:55:34 2011
@@ -14,67 +14,51 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-package org.apache.logging.log4j.core.appender.routing;
+package org.apache.logging.log4j.core.appender.rewrite;
 
 import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.AppenderBase;
 import org.apache.logging.log4j.core.config.AppenderControl;
 import org.apache.logging.log4j.core.config.Configuration;
-import org.apache.logging.log4j.core.config.Node;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
-import org.apache.logging.log4j.core.filter.CompositeFilter;
 
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
 /**
- * This Appender "routes" between various Appenders, some of which can be references to
- * Appenders defined earlier in the configuration while others can be dynamically created
- * within this Appender as required. Routing is achieved by specifying a pattern on
- * the Routing appender declaration. The pattern should contain one or more substitution patterns of
- * the form "$${[key:]token}". The pattern will be resolved each time the Appender is called using
- * the built in StrSubstitutor and the StrLookup plugin that matches the specified key.
+ * This Appender allows the logging event to be manipulated before it is processed by other Appenders.
  */
-@Plugin(name="Routing",type="Core",elementType="appender",printObject=true)
-public class RoutingAppender extends AppenderBase {
-    private static final String DEFAULT_KEY = "ROUTING_APPENDER_DEFAULT";
-    private final Routes routes;
+@Plugin(name="Rewrite",type="Core",elementType="appender",printObject=true)
+public class RewriteAppender extends AppenderBase {
     private final Configuration config;
     private ConcurrentMap<String, AppenderControl> appenders = new ConcurrentHashMap<String, AppenderControl>();
+    private final RewritePolicy rewritePolicy;
+    private final String[] appenderRefs;
 
-    private RoutingAppender(String name, CompositeFilter filters, boolean handleException, Routes routes,
-                            Configuration config) {
-        super(name, filters, null, handleException);
-        this.routes = routes;
+    private RewriteAppender(String name, Filter filter, boolean handleException, String[] appenderRefs,
+                            RewritePolicy rewritePolicy, Configuration config) {
+        super(name, filter, null, handleException);
         this.config = config;
+        this.rewritePolicy = rewritePolicy;
+        this.appenderRefs = appenderRefs;
     }
 
     @Override
     public void start() {
         Map<String, Appender> map = config.getAppenders();
-        for (Route route : routes.getRoutes()) {
-            if (route.getAppenderRef() != null) {
-                Appender appender = map.get(route.getAppenderRef());
-                if (appender != null) {
-                    String key = route.getKey() == null ? DEFAULT_KEY : route.getKey();
-                    if (appenders.containsKey(key)) {
-                        if (DEFAULT_KEY.equals(key)) {
-                            logger.error("Multiple default routes. Only the first will be used");
-                        } else {
-                            logger.error("Duplicate route " + key + " is ignored");
-                        }
-                    } else {
-                        appenders.put(key, new AppenderControl(appender));
-                    }
-                } else {
-                    logger.error("Appender " + route.getAppenderRef() + " cannot be located. Route ignored");
-                }
+        for (String ref : appenderRefs) {
+            Appender appender = map.get(ref);
+            if (appender != null) {
+                appenders.put(ref, new AppenderControl(appender));
+            } else {
+                logger.error("Appender " + ref + " cannot be located. Reference ignored");
             }
         }
         super.start();
@@ -91,90 +75,33 @@ public class RoutingAppender extends App
     }
 
     public void append(LogEvent event) {
-        String key = config.getSubst().replace(event, routes.getPattern());
-        AppenderControl control = getControl(key, event);
-        if (control != null) {
-            control.callAppender(event);
-        }
-    }
-
-    private synchronized AppenderControl getControl(String key, LogEvent event) {
-        AppenderControl control = appenders.get(key);
-        boolean defaultRoute = false;
-        if (control != null) {
-            return control;
-        }
-        Route route = null;
-        for (Route r : routes.getRoutes()) {
-            if (r.getAppenderRef() == null && key.equals(r.getKey())) {
-                route = r;
-                break;
-            }
+        if (rewritePolicy != null) {
+            event = rewritePolicy.rewrite(event);
         }
-        if (route == null) {
-            control = appenders.get(DEFAULT_KEY);
-            if (control != null) {
-                return control;
-            }
-            for (Route r : routes.getRoutes()) {
-                if (r.getAppenderRef() == null && r.getKey() == null) {
-                    route = r;
-                    defaultRoute = true;
-                    break;
-                }
-            }
-        }
-        if (route != null) {
-            Appender app = createAppender(route, event);
-            if (app == null) {
-                return null;
-            }
-            control = new AppenderWrapper(app);
-            appenders.put(key, control);
-            if (defaultRoute) {
-                appenders.put(DEFAULT_KEY, control);
-            }
-        }
-
-        return control;
-    }
-
-    private Appender createAppender(Route route, LogEvent event) {
-        Node routeNode = route.getNode();
-        for (Node node : routeNode.getChildren()) {
-            if (node.getType().getElementName().equals("appender")) {
-                config.createConfiguration(node, event);
-                if (node.getObject() instanceof Appender) {
-                    Appender app = (Appender) node.getObject();
-                    app.start();
-                    return (Appender) node.getObject();
-                }
-                logger.error("Unable to create Appender of type " + node.getName());
-                return null;
-            }
+        for (AppenderControl control : appenders.values()) {
+            control.callAppender(event);
         }
-        logger.error("No Appender was configured for route " + route.getKey());
-        return null;
     }
 
     @PluginFactory
-    public static RoutingAppender createAppender(@PluginAttr("name") String name,
+    public static RewriteAppender createAppender(@PluginAttr("name") String name,
                                           @PluginAttr("suppressExceptions") String suppress,
-                                          @PluginElement("routes") Routes routes,
+                                          @PluginElement("appender-ref") String[] appenderRefs,
                                           @PluginConfiguration Configuration config,
-                                          @PluginElement("filters") CompositeFilter filters) {
+                                          @PluginElement("rewritePolicy") RewritePolicy rewritePolicy,
+                                          @PluginElement("filters") Filter filter) {
 
         boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
 
         if (name == null) {
-            logger.error("No name provided for RoutingAppender");
+            logger.error("No name provided for RewriteAppender");
             return null;
         }
-        if (routes == null) {
-            logger.error("No routes defined for RoutingAppender");
+        if (appenderRefs == null) {
+            logger.error("No appender references defined for RewriteAppender");
             return null;
         }
-        return new RoutingAppender(name, filters, handleExceptions, routes, config);
+        return new RewriteAppender(name, filter, handleExceptions, appenderRefs, rewritePolicy, config);
     }
 
     private static class AppenderWrapper extends AppenderControl {

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewritePolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewritePolicy.java?rev=1190159&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewritePolicy.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/rewrite/RewritePolicy.java Fri Oct 28 04:55:34 2011
@@ -0,0 +1,33 @@
+/*
+ * 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.appender.rewrite;
+
+import org.apache.logging.log4j.core.LogEvent;
+
+/**
+ * Interface to be implemented by components that support modifications to the LogEvent.
+ */
+
+public interface RewritePolicy {
+    /**
+     * Rewrite a logging event.
+     * @param source a logging event that may be returned or
+     * used to create a new logging event.
+     * @return a logging event or null to suppress processing.
+     */
+    LogEvent rewrite(final LogEvent source);
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/routing/RoutingAppender.java Fri Oct 28 04:55:34 2011
@@ -17,8 +17,10 @@
 package org.apache.logging.log4j.core.appender.routing;
 
 import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.AppenderBase;
+import org.apache.logging.log4j.core.appender.rewrite.RewritePolicy;
 import org.apache.logging.log4j.core.config.AppenderControl;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.Node;
@@ -47,12 +49,14 @@ public class RoutingAppender extends App
     private final Routes routes;
     private final Configuration config;
     private ConcurrentMap<String, AppenderControl> appenders = new ConcurrentHashMap<String, AppenderControl>();
+    private final RewritePolicy rewritePolicy;
 
-    private RoutingAppender(String name, CompositeFilter filters, boolean handleException, Routes routes,
-                            Configuration config) {
-        super(name, filters, null, handleException);
+    private RoutingAppender(String name, Filter filter, boolean handleException, Routes routes,
+                            RewritePolicy rewritePolicy, Configuration config) {
+        super(name, filter, null, handleException);
         this.routes = routes;
         this.config = config;
+        this.rewritePolicy = rewritePolicy;
     }
 
     @Override
@@ -91,6 +95,9 @@ public class RoutingAppender extends App
     }
 
     public void append(LogEvent event) {
+        if (rewritePolicy != null) {
+            event = rewritePolicy.rewrite(event);
+        }
         String key = config.getSubst().replace(event, routes.getPattern());
         AppenderControl control = getControl(key, event);
         if (control != null) {
@@ -162,7 +169,8 @@ public class RoutingAppender extends App
                                           @PluginAttr("suppressExceptions") String suppress,
                                           @PluginElement("routes") Routes routes,
                                           @PluginConfiguration Configuration config,
-                                          @PluginElement("filters") CompositeFilter filters) {
+                                          @PluginElement("rewritePolicy") RewritePolicy rewritePolicy,
+                                          @PluginElement("filters") Filter filter) {
 
         boolean handleExceptions = suppress == null ? true : Boolean.valueOf(suppress);
 
@@ -174,7 +182,7 @@ public class RoutingAppender extends App
             logger.error("No routes defined for RoutingAppender");
             return null;
         }
-        return new RoutingAppender(name, filters, handleExceptions, routes, config);
+        return new RoutingAppender(name, filter, handleExceptions, routes, rewritePolicy, config);
     }
 
     private static class AppenderWrapper extends AppenderControl {

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java (from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java&r1=1188557&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/MapFilter.java Fri Oct 28 04:55:34 2011
@@ -23,6 +23,8 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 
@@ -32,13 +34,13 @@ import java.util.Map;
 /**
  *
  */
-@Plugin(name="StructuredDataFilter", type="Core", elementType="filter", printObject=true)
-public class StructuredDataFilter extends FilterBase {
-    private final Map<String, Object> map;
+@Plugin(name="MapFilter", type="Core", elementType="filter", printObject=true)
+public class MapFilter extends FilterBase {
+    private final Map<String, String> map;
 
     private final boolean isAnd;
 
-    private StructuredDataFilter(Map<String, Object> map, boolean oper, Result onMatch, Result onMismatch) {
+    protected MapFilter(Map<String, String> map, boolean oper, Result onMatch, Result onMismatch) {
         super(onMatch, onMismatch);
         if (map == null) {
             throw new NullPointerException("key cannot be null");
@@ -49,8 +51,8 @@ public class StructuredDataFilter extend
 
     @Override
     public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
-        if (msg instanceof StructuredDataMessage) {
-            return filter((StructuredDataMessage)msg);
+        if (msg instanceof MapMessage) {
+            return filter((MapMessage)msg);
         }
         return Result.NEUTRAL;
     }
@@ -58,27 +60,17 @@ public class StructuredDataFilter extend
     @Override
     public Result filter(LogEvent event) {
         Message msg = event.getMessage();
-        if (msg instanceof StructuredDataMessage) {
-            return filter((StructuredDataMessage) msg);
+        if (msg instanceof MapMessage) {
+            return filter((MapMessage) msg);
         }
         return Result.NEUTRAL;
     }
 
-    private Result filter(StructuredDataMessage msg) {
+    protected Result filter(MapMessage msg) {
         boolean match = false;
         for (String key : map.keySet()) {
-            if (key.equalsIgnoreCase("id")) {
-                match = map.get(key).equals(msg.getId().toString());
-            } else if (key.equalsIgnoreCase("id.name")) {
-                match = map.get(key).equals(msg.getId().getName());
-            } else if (key.equalsIgnoreCase("type")) {
-                match = map.get(key).equals(msg.getType());
-            } else if (key.equalsIgnoreCase("message")) {
-                match = map.get(key).equals(msg.getFormattedMessage().toString());
-            } else {
-                String data = msg.getData().get(key).toString();
-                match = map.get(key).equals(data);
-            }
+            String data = msg.getData().get(key);
+            match = map.get(key).equals(data);
             if ((!isAnd && match) || (isAnd && !match)) {
                 break;
             }
@@ -92,7 +84,7 @@ public class StructuredDataFilter extend
         if (map.size() > 0) {
             sb.append(", {");
             boolean first = true;
-            for (Map.Entry<String, Object> entry : map.entrySet()) {
+            for (Map.Entry<String, String> entry : map.entrySet()) {
                 if (!first) {
                     sb.append(", ");
                 }
@@ -104,35 +96,44 @@ public class StructuredDataFilter extend
         return sb.toString();
     }
 
+    protected boolean isAnd() {
+        return isAnd;
+    }
+
+    protected Map<String, String> getMap() {
+        return map;
+    }
+
     @PluginFactory
-    public static StructuredDataFilter createFilter(@PluginAttr("pairs") KeyValuePair[] pairs,
+    public static MapFilter createFilter(@PluginAttr("pairs") KeyValuePair[] pairs,
                                                     @PluginAttr("operator") String oper,
                                                     @PluginAttr("onmatch") String match,
                                                     @PluginAttr("onmismatch") String mismatch) {
         if (pairs == null || pairs.length == 0) {
-            logger.error("keys and values must be specified for the ThreadContextMapFilter");
+            logger.error("keys and values must be specified for the MapFilter");
+            return null;
         }
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, String> map = new HashMap<String, String>();
         for (KeyValuePair pair : pairs) {
             String key = pair.getKey();
             if (key == null) {
-                logger.error("A null key is not valid in StructuredDataFilter");
+                logger.error("A null key is not valid in MapFilter");
                 continue;
             }
             String value = pair.getValue();
             if (value == null) {
-                logger.error("A null value for key " + key + " is not allowed in StructuredDataFilter");
+                logger.error("A null value for key " + key + " is not allowed in MapFilter");
                 continue;
             }
             map.put(pair.getKey(), pair.getValue());
         }
         if (map.size() == 0) {
-            logger.error("StructuredDataFilter is not configured with any valid key value pairs");
+            logger.error("MapFilter is not configured with any valid key value pairs");
             return null;
         }
         boolean isAnd = oper == null || !oper.equalsIgnoreCase("or");
         Result onMatch = match == null ? null : Result.valueOf(match);
         Result onMismatch = mismatch == null ? null : Result.valueOf(mismatch);
-        return new StructuredDataFilter(map, isAnd, onMatch, onMismatch);
+        return new MapFilter(map, isAnd, onMatch, onMismatch);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/StructuredDataFilter.java Fri Oct 28 04:55:34 2011
@@ -23,6 +23,8 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 
@@ -33,18 +35,10 @@ import java.util.Map;
  *
  */
 @Plugin(name="StructuredDataFilter", type="Core", elementType="filter", printObject=true)
-public class StructuredDataFilter extends FilterBase {
-    private final Map<String, Object> map;
+public class StructuredDataFilter extends MapFilter {
 
-    private final boolean isAnd;
-
-    private StructuredDataFilter(Map<String, Object> map, boolean oper, Result onMatch, Result onMismatch) {
-        super(onMatch, onMismatch);
-        if (map == null) {
-            throw new NullPointerException("key cannot be null");
-        }
-        this.isAnd = oper;
-        this.map = map;
+    private StructuredDataFilter(Map<String, String> map, boolean oper, Result onMatch, Result onMismatch) {
+        super(map, oper, onMatch, onMismatch);
     }
 
     @Override
@@ -64,8 +58,13 @@ public class StructuredDataFilter extend
         return Result.NEUTRAL;
     }
 
-    private Result filter(StructuredDataMessage msg) {
+    protected Result filter(MapMessage message) {
+        if (!(message instanceof StructuredDataMessage)) {
+            return super.filter(message);
+        }
+        StructuredDataMessage msg = (StructuredDataMessage) message;
         boolean match = false;
+        Map<String, String> map = getMap();
         for (String key : map.keySet()) {
             if (key.equalsIgnoreCase("id")) {
                 match = map.get(key).equals(msg.getId().toString());
@@ -79,7 +78,7 @@ public class StructuredDataFilter extend
                 String data = msg.getData().get(key).toString();
                 match = map.get(key).equals(data);
             }
-            if ((!isAnd && match) || (isAnd && !match)) {
+            if ((!isAnd() && match) || (isAnd() && !match)) {
                 break;
             }
         }
@@ -88,11 +87,11 @@ public class StructuredDataFilter extend
 
     public String toString() {
         StringBuilder sb = new StringBuilder();
-        sb.append("isAnd=").append(isAnd);
-        if (map.size() > 0) {
+        sb.append("isAnd=").append(isAnd());
+        if (getMap().size() > 0) {
             sb.append(", {");
             boolean first = true;
-            for (Map.Entry<String, Object> entry : map.entrySet()) {
+            for (Map.Entry<String, String> entry : getMap().entrySet()) {
                 if (!first) {
                     sb.append(", ");
                 }
@@ -110,9 +109,10 @@ public class StructuredDataFilter extend
                                                     @PluginAttr("onmatch") String match,
                                                     @PluginAttr("onmismatch") String mismatch) {
         if (pairs == null || pairs.length == 0) {
-            logger.error("keys and values must be specified for the ThreadContextMapFilter");
+            logger.error("keys and values must be specified for the StructuredDataFilter");
+            return null;
         }
-        Map<String, Object> map = new HashMap<String, Object>();
+        Map<String, String> map = new HashMap<String, String>();
         for (KeyValuePair pair : pairs) {
             String key = pair.getKey();
             if (key == null) {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilter.java Fri Oct 28 04:55:34 2011
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.apache.logging.log4j.message.Message;
 
 import java.util.HashMap;

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java (from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/KeyValuePair.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/KeyValuePair.java&r1=1188547&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/filter/KeyValuePair.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/helpers/KeyValuePair.java Fri Oct 28 04:55:34 2011
@@ -14,9 +14,8 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-package org.apache.logging.log4j.core.filter;
+package org.apache.logging.log4j.core.helpers;
 
-import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 import org.apache.logging.log4j.core.config.plugins.PluginAttr;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java Fri Oct 28 04:55:34 2011
@@ -128,6 +128,10 @@ public class Log4jLogEvent implements Lo
         return marker;
     }
 
+    public String getFQCN() {
+        return fqcnOfLogger;
+    }
+
     /**
      * @doubt Allows direct access to the map passed into the constructor, would allow appender
      * or layout to manipulate event as seen by other appenders.

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java (from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java&r1=1188547&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/RoutingAppenderTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/RewriteAppenderTest.java Fri Oct 28 04:55:34 2011
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-package org.apache.logging.log4j.core.appender.routing;
+package org.apache.logging.log4j.core.appender.rewrite;
 
 import org.apache.logging.log4j.EventLogger;
 import org.apache.logging.log4j.LogManager;
@@ -24,6 +24,8 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.appender.ListAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.apache.logging.log4j.message.MapMessage;
+import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.junit.AfterClass;
@@ -34,15 +36,15 @@ import java.io.File;
 import java.util.List;
 import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
 
 /**
  *
  */
-public class RoutingAppenderTest {
-    private static final String CONFIG = "log4j-routing.xml";
+public class RewriteAppenderTest {
+    private static final String CONFIG = "log4j-rewrite.xml";
     private static Configuration config;
     private static ListAppender app;
     private static LoggerContext ctx;
@@ -58,8 +60,6 @@ public class RoutingAppenderTest {
                 break;
             }
         }
-        File file = new File("target/rolling1/rollingtest-Unknown.log");
-        file.delete();
     }
 
     @AfterClass
@@ -67,20 +67,25 @@ public class RoutingAppenderTest {
         System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
         ctx.reconfigure();
         StatusLogger.getLogger().reset();
-        File file = new File("target/rolling1/rollingtest-Unknown.log");
-        file.delete();
     }
 
     @Test
-    public void routingTest() {
+    public void rewriteTest() {
         StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service");
+        msg.put("Key1", "Value1");
+        msg.put("Key2", "Value2");
         EventLogger.logEvent(msg);
         List<LogEvent> list = app.getEvents();
         assertNotNull("No events generated", list);
         assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
-        msg = new StructuredDataMessage("Test", "This is a test", "Unknown");
-        EventLogger.logEvent(msg);
-        File file = new File("target/rolling1/rollingtest-Unknown.log");
-        assertTrue("File was not created", file.exists());
+        LogEvent event = list.get(0);
+        Message m = event.getMessage();
+        assertTrue("Message is not a MapMessage", m instanceof MapMessage);
+        MapMessage message = (MapMessage) m;
+        Map<String, String> map = message.getData();
+        assertNotNull("No Map", map);
+        assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size() == 3);
+        String value = map.get("Key1");
+        assertEquals("Apache", value);
     }
 }

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java?rev=1190159&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/TestRewritePolicy.java Fri Oct 28 04:55:34 2011
@@ -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.appender.rewrite;
+
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginFactory;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.Message;
+
+import java.util.Map;
+
+/**
+ *
+ */
+@Plugin(name = "TestRewritePolicy", type = "Core", elementType = "rewritePolicy", printObject = true)
+public class TestRewritePolicy implements RewritePolicy {
+
+    public LogEvent rewrite(LogEvent source) {
+
+        return new Log4jLogEvent(source.getLoggerName(), source.getMarker(), source.getFQCN(), source.getLevel(),
+            source.getMessage(), source.getThrown(), source.getContextMap(), source.getContextStack(),
+            source.getThreadName(), source.getSource(), source.getMillis());
+    }
+
+    @PluginFactory
+    public static TestRewritePolicy createPolicy() {
+        return new TestRewritePolicy();
+    }
+}

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MapFilterTest.java (from r1188547, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MapFilterTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MapFilterTest.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java&r1=1188547&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/MapFilterTest.java Fri Oct 28 04:55:34 2011
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
+import org.apache.logging.log4j.message.MapMessage;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.junit.Test;
 
@@ -26,16 +28,16 @@ import static org.junit.Assert.assertTru
 /**
  *
  */
-public class StructuredDataFilterTest {
+public class MapFilterTest {
 
 
     @Test
     public void testFilter() {
-        KeyValuePair[] pairs = new KeyValuePair[] { new KeyValuePair("id.name", "AccountTransfer"),
+        KeyValuePair[] pairs = new KeyValuePair[] { new KeyValuePair("FromAccount", "211000"),
                                                     new KeyValuePair("ToAccount", "123456")};
-        StructuredDataFilter filter = StructuredDataFilter.createFilter(pairs, "and", null, null);
+        MapFilter filter = MapFilter.createFilter(pairs, "and", null, null);
         filter.start();
-        StructuredDataMessage msg = new StructuredDataMessage("AccountTransfer@18060", "Transfer Successful", "Audit");
+        MapMessage msg = new MapMessage();
         msg.put("ToAccount", "123456");
         msg.put("FromAccount", "211000");
         msg.put("Amount", "1000.00");
@@ -43,9 +45,9 @@ public class StructuredDataFilterTest {
         assertTrue(filter.filter(null, Level.DEBUG, null, msg, (Throwable)null) == Filter.Result.NEUTRAL);
         msg.put("ToAccount", "111111");
         assertTrue(filter.filter(null, Level.ERROR, null, msg, (Throwable)null) == Filter.Result.DENY);
-        filter = StructuredDataFilter.createFilter(pairs, "or", null, null);
+        filter = MapFilter.createFilter(pairs, "or", null, null);
         filter.start();
-        msg = new StructuredDataMessage("AccountTransfer@18060", "Transfer Successful", "Audit");
+        msg = new MapMessage();
         msg.put("ToAccount", "123456");
         msg.put("FromAccount", "211000");
         msg.put("Amount", "1000.00");

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/StructuredDataFilterTest.java Fri Oct 28 04:55:34 2011
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.fi
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.junit.Test;
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilterTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilterTest.java?rev=1190159&r1=1190158&r2=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilterTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/filter/ThreadContextMapFilterTest.java Fri Oct 28 04:55:34 2011
@@ -19,6 +19,7 @@ package org.apache.logging.log4j.core.fi
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.junit.Test;
 
 import static org.junit.Assert.assertTrue;

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-rewrite.xml (from r1188557, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.xml)
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-rewrite.xml?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-rewrite.xml&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.xml&r1=1188557&r2=1190159&rev=1190159&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-rewrite.xml Fri Oct 28 04:55:34 2011
@@ -1,9 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration packages="" status="debug" name="RoutingTest">
-  <properties>
-    <property name="filename">target/rolling1/rollingtest-$${sd:type}.log</property>
-  </properties>
-  <ThresholdFilter level="debug"/>
+<configuration packages="" status="error" name="RoutingTest">
 
   <appenders>
     <Console name="STDOUT">
@@ -12,26 +8,19 @@
     <List name="List">
       <ThresholdFilter level="debug"/>
     </List>
-    <Routing name="Routing">
-      <Routes pattern="$${sd:type}">
-        <Route>
-          <RollingFile name="Rolling-${sd:type}" fileName="${filename}"
-                       filePattern="target/rolling1/test1-${sd:type}.%i.log.gz">
-            <PatternLayout>
-              <pattern>%d %p %C{1.} [%t] %m%n</pattern>
-            </PatternLayout>
-            <SizeBasedTriggeringPolicy size="500" />
-          </RollingFile>
-        </Route>
-        <Route appender-ref="STDOUT" key="Audit"/>
-        <Route appender-ref="List" key="Service"/>
-      </Routes>
-    </Routing>
+    <Rewrite name="Rewrite">
+      <MapRewritePolicy>
+        <KeyValuePair key="Key1" Value="Apache"/>
+        <KeyValuePair key="Key3" Value="Log4j"/>
+      </MapRewritePolicy>
+      <appender-ref ref="List"/>
+
+    </Rewrite>
   </appenders>
 
   <loggers>
-    <logger name="EventLogger" level="info" additivity="false">
-      <appender-ref ref="Routing"/>
+    <logger name="EventLogger" level="trace" additivity="false">
+      <appender-ref ref="Rewrite"/>
     </logger>
 
     <root level="error">



Mime
View raw message