You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2011/11/21 21:47:56 UTC

svn commit: r1204693 - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j2-core/ log4j2-core/src/main/java/org/apache/logging/log4j/core/config/ log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/ log4j2-core/src/tes...

Author: rgoers
Date: Mon Nov 21 20:47:56 2011
New Revision: 1204693

URL: http://svn.apache.org/viewvc?rev=1204693&view=rev
Log:
Add support for JSON configuration

Added:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
      - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
      - copied, changed from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/JSONRoutingAppenderTest.java
      - copied, changed from r1196435, 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/resources/log4j-routing.json
Modified:
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml
    logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/lookups.xml

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml?rev=1204693&r1=1204692&r2=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/pom.xml Mon Nov 21 20:47:56 2011
@@ -36,6 +36,18 @@
       <groupId>org.apache.logging.rgoers</groupId>
       <artifactId>log4j2-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-core-asl</artifactId>
+      <version>1.9.2</version>
+      <optional>true</optional>
+     </dependency>
+     <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-mapper-asl</artifactId>
+      <version>1.9.2</version>
+      <optional>true</optional>
+    </dependency>
 	  <dependency>
       <groupId>oro</groupId>
       <artifactId>oro</artifactId>

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.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/config/BaseConfiguration.java?rev=1204693&r1=1204692&r2=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java Mon Nov 21 20:47:56 2011
@@ -586,7 +586,11 @@ public class BaseConfiguration extends F
                     }
                 } else if (a instanceof PluginValue) {
                     String name = ((PluginValue)a).value();
-                    String value = subst.replace(event, node.getValue());
+                    String v = node.getValue();
+                    if (v == null) {
+                        v = getAttrValue("value", attrs);
+                    }
+                    String value = subst.replace(event, v);
                     sb.append(name +"=" + "\"" + value + "\"");
                     parms[index] = value;
                 } else if (a instanceof PluginAttr) {

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.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/config/JSONConfiguration.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java&r1=1195339&r2=1204693&rev=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java Mon Nov 21 20:47:56 2011
@@ -23,24 +23,10 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.status.StatusConsoleListener;
 import org.apache.logging.log4j.status.StatusListener;
 import org.apache.logging.log4j.status.StatusLogger;
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.map.ObjectMapper;
 import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
 
-import javax.xml.XMLConstants;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Validator;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -52,36 +38,31 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * Creates a Node hierarchy from an XML file.
+ * Creates a Node hierarchy from a JSON file.
  */
-public class XMLConfiguration extends BaseConfiguration {
-
+public class JSONConfiguration extends BaseConfiguration {
     private List<Status> status = new ArrayList<Status>();
 
-    private Element rootElement = null;
-
-    private boolean strict = false;
-
     private static final String[] verboseClasses = new String[] { ResolverUtil.class.getName() };
 
-    private Validator validator;
-
-    private static final String LOG4J_XSD = "Log4J-V2.0.xsd";
+    private JsonNode root;
 
-    public XMLConfiguration(InputSource source, File configFile) {
-        byte[] buffer = null;
+    public JSONConfiguration(InputSource source, File configFile) {
+        byte[] buffer;
 
         try {
             buffer = toByteArray(source.getByteStream());
-            source = new InputSource(new ByteArrayInputStream(buffer));
-            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-            Document document = builder.parse(source);
-            rootElement = document.getDocumentElement();
-            Map<String, String> attrs = processAttributes(rootNode, rootElement);
+            InputStream is = new ByteArrayInputStream(buffer);
+            source = new InputSource(is);
+            root = new ObjectMapper().readTree(is);
+            if (root.size() == 1) {
+                Iterator<JsonNode> i = root.getElements();
+                root = i.next();
+            }
+            processAttributes(rootNode, root);
             Level status = Level.OFF;
             boolean verbose = false;
-
-            for (Map.Entry<String, String> entry : attrs.entrySet()) {
+            for (Map.Entry<String, String> entry : rootNode.getAttributes().entrySet()) {
                 if ("status".equalsIgnoreCase(entry.getKey())) {
                     status = Level.toLevel(entry.getValue().toUpperCase(), Level.OFF);
                 } else if ("verbose".equalsIgnoreCase(entry.getKey())) {
@@ -93,8 +74,6 @@ public class XMLConfiguration extends Ba
                     }
                 } else if ("name".equalsIgnoreCase(entry.getKey())) {
                     setName(entry.getValue());
-                } else if ("strict".equalsIgnoreCase(entry.getKey())) {
-                    strict = Boolean.parseBoolean(entry.getValue());
                 } else if ("monitorInterval".equalsIgnoreCase(entry.getKey())) {
                     int interval = Integer.parseInt(entry.getValue());
                     if (interval > 0 && configFile != null) {
@@ -102,15 +81,16 @@ public class XMLConfiguration extends Ba
                     }
                 }
             }
-            Iterator<StatusListener> iter = ((StatusLogger)logger).getListeners();
+
+            Iterator<StatusListener> statusIter = ((StatusLogger) logger).getListeners();
             boolean found = false;
-            while (iter.hasNext()) {
-                StatusListener listener = iter.next();
+            while (statusIter.hasNext()) {
+                StatusListener listener = statusIter.next();
                 if (listener instanceof StatusConsoleListener) {
                     found = true;
                     ((StatusConsoleListener) listener).setLevel(status);
                     if (!verbose) {
-                        ((StatusConsoleListener)listener).setFilters(verboseClasses);
+                        ((StatusConsoleListener) listener).setFilters(verboseClasses);
                     }
                 }
             }
@@ -121,106 +101,102 @@ public class XMLConfiguration extends Ba
                 }
                 ((StatusLogger) logger).registerListener(listener);
             }
-
-        } catch (SAXException domEx) {
-            logger.error("Error parsing " + source.getSystemId(), domEx);
-        } catch (IOException ioe) {
-            logger.error("Error parsing " + source.getSystemId(), ioe);
-        } catch (ParserConfigurationException pex) {
-            logger.error("Error parsing " + source.getSystemId(), pex);
-        }
-        if (strict && buffer != null) {
-            InputStream is = getClass().getClassLoader().getResourceAsStream(LOG4J_XSD);
-            Source src = new StreamSource(is, LOG4J_XSD);
-            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
-            Schema schema = null;
-            try {
-                schema = factory.newSchema(src);
-            } catch (SAXException ex) {
-                logger.error("Error parsing Log4j schema", ex);
-            }
-            if (schema != null) {
-                validator = schema.newValidator();
-                try {
-                    validator.validate(new StreamSource(new ByteArrayInputStream(buffer)));
-                } catch (IOException ioe) {
-                    logger.error("Error reading configuration for validation", ioe);
-                } catch (SAXException ex) {
-                    logger.error("Error validating configuration", ex);
-                }
+            if (getName() == null) {
+                setName(source.getSystemId());
             }
-        }
-
-        if (getName() == null) {
-            setName(source.getSystemId());
+        } catch (Exception ex) {
+            logger.error("Error parsing " + source.getSystemId(), ex);
+            ex.printStackTrace();
         }
     }
 
-    public void setup() {
-        constructHierarchy(rootNode, rootElement);
+     public void setup() {
+        Iterator<Map.Entry<String, JsonNode>> iter = root.getFields();
+        List<Node> children = rootNode.getChildren();
+        while (iter.hasNext()) {
+            Map.Entry<String, JsonNode> entry = iter.next();
+            JsonNode n = entry.getValue();
+            if (n.isObject()) {
+                logger.debug("Processing node for object " + entry.getKey());
+                children.add(constructNode(entry.getKey(), rootNode, n));
+            } else if (n.isArray()) {
+                logger.error("Arrays are not supported at the root configuration.");
+            }
+        }
+        logger.debug("Completed parsing configuration");
         if (status.size() > 0) {
             for (Status s : status) {
                 logger.error("Error processing element " + s.name + ": " + s.errorType);
             }
             return;
         }
-        rootElement = null;
     }
 
-    private void constructHierarchy(Node node, Element element) {
-        processAttributes(node, element);
-        StringBuffer buffer = new StringBuffer();
-        NodeList list = element.getChildNodes();
+    private Node constructNode(String name, Node parent, JsonNode jsonNode) {
+        PluginType type = getPluginManager().getPluginType(name);
+        Node node = new Node(parent, name, type);
+        processAttributes(node, jsonNode);
+        Iterator<Map.Entry<String, JsonNode>> iter = jsonNode.getFields();
         List<Node> children = node.getChildren();
-        for (int i = 0; i < list.getLength(); i++) {
-            org.w3c.dom.Node w3cNode = list.item(i);
-            if (w3cNode instanceof Element) {
-                Element child = (Element) w3cNode;
-                String name = getType(child);
-                PluginType type = getPluginManager().getPluginType(name);
-                Node childNode = new Node(node, name, type);
-                constructHierarchy(childNode, child);
+        while (iter.hasNext()) {
+            Map.Entry<String, JsonNode> entry = iter.next();
+            JsonNode n = entry.getValue();
+            if (n.isArray() || n.isObject()) {
                 if (type == null) {
-                    String value = childNode.getValue();
-                    if (!childNode.hasChildren() && value != null) {
-                        node.getAttributes().put(name, value);
-                    } else {
-                        status.add(new Status(name, element, ErrorType.CLASS_NOT_FOUND));
+                    status.add(new Status(name, n, ErrorType.CLASS_NOT_FOUND));
+                }
+                if (n.isArray()) {
+                    logger.debug("Processing node for array " + entry.getKey());
+                    for (int i=0; i < n.size(); ++i) {
+                        PluginType entryType = getPluginManager().getPluginType(entry.getKey());
+                        Node item = new Node(node, entry.getKey(), entryType);
+                        processAttributes(item, n.get(i));
+                        logger.debug("Processing " + entry.getKey() + "[" + i + "]");
+                        Iterator<Map.Entry<String, JsonNode>> itemIter = n.get(i).getFields();
+                        List<Node> itemChildren = item.getChildren();
+                        while (itemIter.hasNext()) {
+                            Map.Entry<String, JsonNode> itemEntry = itemIter.next();
+                            if (itemEntry.getValue().isObject()) {
+                                logger.debug("Processing node for object " + itemEntry.getKey());
+                                itemChildren.add(constructNode(itemEntry.getKey(), item, itemEntry.getValue()));
+                            }
+                        }
+                        children.add(item);
                     }
                 } else {
-                    children.add(childNode);
+                    logger.debug("Processing node for object " + entry.getKey());
+                    children.add(constructNode(entry.getKey(), node, n));
                 }
-            } else if (w3cNode instanceof Text) {
-                Text data = (Text) w3cNode;
-                buffer.append(data.getData());
+
+
             }
         }
 
-        String text = buffer.toString().trim();
-        if (text.length() > 0 || (!node.hasChildren() && !node.isRoot())) {
-            node.setValue(text);
+        String t;
+        if (type == null) {
+            t = "null";
+        } else {
+            t = type.getElementName() + ":" + type.getPluginClass();
         }
+
+        String p = node.getParent() == null ? "null" : node.getParent().getName() == null ? "root" : node.getParent().getName();
+        logger.debug("Returning " + node.getName() + " with parent " + p + " of type " +  t);
+        return node;
     }
 
-    private String getType(Element element) {
-        if (strict) {
-            NamedNodeMap attrs = element.getAttributes();
-            for (int i= 0; i < attrs.getLength(); ++i) {
-                org.w3c.dom.Node w3cNode = attrs.item(i);
-                if (w3cNode instanceof Attr) {
-                    Attr attr = (Attr) w3cNode;
-                    if (attr.getName().equalsIgnoreCase("type")) {
-                        String type = attr.getValue();
-                        attrs.removeNamedItem(attr.getName());
-                        return type;
-                    }
-                }
+    private void processAttributes(Node parent, JsonNode node) {
+        Map<String, String> attrs = parent.getAttributes();
+        Iterator<Map.Entry<String, JsonNode>> iter = node.getFields();
+        while (iter.hasNext()) {
+            Map.Entry<String, JsonNode> entry = iter.next();
+            JsonNode n = entry.getValue();
+            if (n.isValueNode()) {
+                attrs.put(entry.getKey(), n.asText());
             }
         }
-        return element.getTagName();
     }
 
-    private byte[] toByteArray(InputStream is) throws IOException {
+    protected byte[] toByteArray(InputStream is) throws IOException {
         ByteArrayOutputStream buffer = new ByteArrayOutputStream();
 
         int nRead;
@@ -233,34 +209,19 @@ public class XMLConfiguration extends Ba
         return buffer.toByteArray();
     }
 
-    private Map<String, String> processAttributes(Node node, Element element) {
-        NamedNodeMap attrs = element.getAttributes();
-        Map<String, String> attributes = node.getAttributes();
-
-        for (int i = 0; i < attrs.getLength(); ++i) {
-            org.w3c.dom.Node w3cNode = attrs.item(i);
-            if (w3cNode instanceof Attr) {
-                Attr attr = (Attr) w3cNode;
-                attributes.put(attr.getName(), attr.getValue());
-            }
-        }
-        return attributes;
-    }
-
-    private enum ErrorType {
+     private enum ErrorType {
         CLASS_NOT_FOUND
     }
 
-    private class Status {
-        Element element;
+     private class Status {
+        JsonNode node;
         String name;
         ErrorType errorType;
 
-        public Status(String name, Element element, ErrorType errorType) {
+        public Status(String name, JsonNode node, ErrorType errorType) {
             this.name = name;
-            this.element = element;
+            this.node = node;
             this.errorType = errorType;
         }
     }
-
 }

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java (from r1195339, logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.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/config/JSONConfigurationFactory.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java&p1=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java&r1=1195339&r2=1204693&rev=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java Mon Nov 21 20:47:56 2011
@@ -16,45 +16,51 @@
  */
 package org.apache.logging.log4j.core.config;
 
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
-import org.apache.logging.log4j.core.helpers.FileUtils;
-import org.apache.logging.log4j.core.helpers.Loader;
-import org.apache.logging.log4j.status.StatusLogger;
 import org.xml.sax.InputSource;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URI;
-import java.net.URL;
 
 /**
  *
  */
-@Plugin(name="XMLConfigurationFactory", type="ConfigurationFactory")
-@Order(5)
-public class XMLConfigurationFactory extends ConfigurationFactory {
+@Plugin(name="JSONConfigurationFactory", type="ConfigurationFactory")
+@Order(6)
+public class JSONConfigurationFactory extends XMLConfigurationFactory {
 
-    public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
+    public static final String DEFAULT_CONFIG_FILE = "log4j2.json";
 
-    public static final String DEFAULT_CONFIG_FILE = "log4j2.xml";
-
-    public static final String TEST_CONFIG_FILE = "log4j2-test.xml";
+    public static final String TEST_CONFIG_FILE = "log4j2-test.json";
 
     public static final String TEST_PREFIX = "log4j2-test";
 
     public static final String DEFAULT_PREFIX = "log4j2";
 
-    public static final String SUFFIX = ".xml";
-
-    private static Logger logger = StatusLogger.getLogger();
+    public static final String SUFFIX = ".json";
 
     private File configFile = null;
 
+    private String[] dependencies = new String[] {
+        "org.codehaus.jackson.JsonNode",
+        "org.codehaus.jackson.map.ObjectMapper"
+    };
+
+    private boolean isActive;
+
+    public JSONConfigurationFactory() {
+        try {
+            for (String item : dependencies) {
+                Class.forName(item);
+            }
+        } catch (ClassNotFoundException ex) {
+            logger.debug("Missing dependencies for Json support");
+            isActive = false;
+            return;
+        }
+        isActive = true;
+    }
+
     public Configuration getConfiguration(String name, URI configLocation) {
         InputSource source = null;
         if (configLocation != null) {
@@ -72,7 +78,7 @@ public class XMLConfigurationFactory ext
                 defaultName = DEFAULT_CONFIG_FILE;
             }
             ClassLoader loader = this.getClass().getClassLoader();
-            source = getInputFromSystemProperty(loader);
+            source = getInputFromSystemProperty(loader, ".json");
             if (source == null) {
                 source = getInputFromResource(testName, loader);
                 if (source == null) {
@@ -83,65 +89,6 @@ public class XMLConfigurationFactory ext
                 }
             }
         }
-        return new XMLConfiguration(source, configFile);
-    }
-
-    private InputSource getInputFromURI(URI configLocation) {
-        configFile = FileUtils.fileFromURI(configLocation);
-        if (configFile != null && configFile.exists() && configFile.canRead()) {
-            try {
-                InputSource source = new InputSource(new FileInputStream(configFile));
-                source.setSystemId(configLocation.getPath());
-                return source;
-            } catch (FileNotFoundException ex) {
-                logger.error("Cannot locate file " + configLocation.getPath(), ex);
-            }
-        }
-        try {
-            InputSource source = new InputSource(configLocation.toURL().openStream());
-            source.setSystemId(configLocation.getPath());
-            return source;
-        } catch (MalformedURLException ex) {
-            logger.error("Invalid URL " + configLocation.toString(), ex);
-        } catch (IOException ex) {
-            logger.error("Unabled to access " + configLocation.toString(), ex);
-        }
-        return null;
-    }
-
-    private InputSource getInputFromSystemProperty(ClassLoader loader) {
-        String configFile = System.getProperty(CONFIGURATION_FILE_PROPERTY);
-        if (configFile == null) {
-            return null;
-        }
-        InputSource source;
-        try {
-            URL url = new URL(configFile);
-            source = new InputSource(url.openStream());
-            source.setSystemId(configFile);
-            return source;
-        } catch (Exception ex) {
-            source = getInputFromResource(configFile, loader);
-            if (source == null) {
-                try {
-                    InputStream is = new FileInputStream(configFile);
-                    source = new InputSource(is);
-                    source.setSystemId(configFile);
-                } catch (FileNotFoundException fnfe) {
-                    // Ignore the exception
-                }
-            }
-        }
-        return source;
-    }
-
-    private InputSource getInputFromResource(String resource, ClassLoader loader) {
-        InputStream is = Loader.getResourceAsStream(resource, loader);
-        if (is == null) {
-            return null;
-        }
-        InputSource source = new InputSource(is);
-        source.setSystemId(resource);
-        return source;
+        return new JSONConfiguration(source, configFile);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.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/config/XMLConfigurationFactory.java?rev=1204693&r1=1204692&r2=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java Mon Nov 21 20:47:56 2011
@@ -51,7 +51,7 @@ public class XMLConfigurationFactory ext
 
     public static final String SUFFIX = ".xml";
 
-    private static Logger logger = StatusLogger.getLogger();
+    protected static Logger logger = StatusLogger.getLogger();
 
     private File configFile = null;
 
@@ -72,7 +72,7 @@ public class XMLConfigurationFactory ext
                 defaultName = DEFAULT_CONFIG_FILE;
             }
             ClassLoader loader = this.getClass().getClassLoader();
-            source = getInputFromSystemProperty(loader);
+            source = getInputFromSystemProperty(loader, null);
             if (source == null) {
                 source = getInputFromResource(testName, loader);
                 if (source == null) {
@@ -86,7 +86,7 @@ public class XMLConfigurationFactory ext
         return new XMLConfiguration(source, configFile);
     }
 
-    private InputSource getInputFromURI(URI configLocation) {
+    protected InputSource getInputFromURI(URI configLocation) {
         configFile = FileUtils.fileFromURI(configLocation);
         if (configFile != null && configFile.exists() && configFile.canRead()) {
             try {
@@ -109,9 +109,9 @@ public class XMLConfigurationFactory ext
         return null;
     }
 
-    private InputSource getInputFromSystemProperty(ClassLoader loader) {
+    protected InputSource getInputFromSystemProperty(ClassLoader loader, String suffix) {
         String configFile = System.getProperty(CONFIGURATION_FILE_PROPERTY);
-        if (configFile == null) {
+        if (configFile == null || (suffix != null && !configFile.toLowerCase().endsWith(suffix.toLowerCase()))) {
             return null;
         }
         InputSource source;
@@ -135,7 +135,7 @@ public class XMLConfigurationFactory ext
         return source;
     }
 
-    private InputSource getInputFromResource(String resource, ClassLoader loader) {
+    protected InputSource getInputFromResource(String resource, ClassLoader loader) {
         InputStream is = Loader.getResourceAsStream(resource, loader);
         if (is == null) {
             return null;

Copied: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/JSONRoutingAppenderTest.java (from r1196435, 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/routing/JSONRoutingAppenderTest.java?p2=logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/routing/JSONRoutingAppenderTest.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=1196435&r2=1204693&rev=1204693&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/routing/JSONRoutingAppenderTest.java Mon Nov 21 20:47:56 2011
@@ -21,11 +21,11 @@ import org.apache.logging.log4j.LogManag
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
-import org.apache.logging.log4j.test.appender.ListAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -34,15 +34,14 @@ 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;
 
 /**
  *
  */
-public class RoutingAppenderTest {
-    private static final String CONFIG = "log4j-routing.xml";
+public class JSONRoutingAppenderTest {
+    private static final String CONFIG = "log4j-routing.json";
     private static Configuration config;
     private static ListAppender app;
     private static LoggerContext ctx;

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.json
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.json?rev=1204693&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.json (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-routing.json Mon Nov 21 20:47:56 2011
@@ -0,0 +1,35 @@
+{ "configuration": { "status": "error", "name": "RoutingTest", "packages": "org.apache.logging.log4j.test",
+      "properties": {
+        "property": { "name": "filename", "value" : "target/rolling1/rollingtest-$${sd:type}.log" }
+      },
+    "ThresholdFilter": { "level": "debug" },
+    "appenders": {
+      "Console": { "name": "STDOUT",
+        "PatternLayout": { "pattern": "%m%n" }
+      },
+      "List": { "name": "List",
+        "ThresholdFilter": { "level": "debug" }
+      },
+      "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"},
+                "SizeBasedTriggeringPolicy": { "size": "500" }
+              }
+            },
+            { "appender-ref": "STDOUT", "key": "Audit"},
+            { "appender-ref": "List", "key": "Service"}
+          ]
+        }
+      }
+    },
+    "loggers": {
+      "logger": { "name": "EventLogger", "level": "info", "additivity": "false", "appender-ref": { "ref": "Routing" }},
+      "root": { "level": "error", "appender-ref": { "ref": "STDOUT" }}
+    }
+  }
+}
\ No newline at end of file

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml?rev=1204693&r1=1204692&r2=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/site.xml Mon Nov 21 20:47:56 2011
@@ -16,6 +16,18 @@
 
 -->
 <project name="Log4j">
+  <skin>
+    <groupId>org.apache.maven.skins</groupId>
+    <artifactId>maven-fluido-skin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </skin>
+  <custom>
+    <fluidoSkin>
+      <topBarEnabled>false</topBarEnabled>
+      <sideBarEnabled>true</sideBarEnabled>
+      <searchEnabled>true</searchEnabled>
+    </fluidoSkin>
+  </custom>
   <bannerLeft>
     <name>Logging Services</name>
     <src>images/ls-logo.jpg</src>
@@ -25,78 +37,80 @@
     <src>images/logo.jpg</src>
   </bannerRight>
   <body>
-    <menu name="Log4j" inherit="top">
-      <item name="Overview"                href="/index.html"/>
-      <item name="Download and Build"      href="/download.html"/>
-      <item name="Log4j 2 API"             href="log4j2-api/api.html"/>
-      <item name="API JavaDocs"            href="log4j2-api/apidocs/index.html"/>
-      <item name="Log4j 1.x API"           href="log4j12-api/api.html"/>
-      <item name="Commons Logging"         href="log4j2-jcl/api.html"/>
-      <item name="SLF4J"                   href="slf4j-impl/api.html"/>
-      <item name="Log4J 2 Manual"          href="/manual/index.html" collapse="true">
-        <item name="Architecture"          href="/manual/architecture.html"/>
-        <item name="Configuration"         href="/manual/configuration.html"/>
-        <item name="Plugins"               href="/manual/plugins.html" collapse="true">
-          <item name="Core"                href="/manual/plugins.html#Core"/>
-          <item name="Converters"          href="/manual/plugins.html#Converters"/>
-          <item name="Lookups"             href="/manual/plugins.html#Lookups"/>
-        </item>
-        <item name="Lookups"               href="/manual/lookups.html" collapse="true">
-          <item name="ContextMap"          href="/manual/lookups.html#ContextMapLookup"/>
-          <item name="StructuredData"      href="/manual/lookups.html#StructuredDataLookup"/>
-          <item name="SystemProperties"    href="/manual/lookups.html#SystemPropertiesLookup"/>
-        </item>
-        <item name="Appenders"             href="/manual/appenders.html" collapse="true">
-          <item name="Console"             href="/manual/appenders.html@ConsoleAppender"/>
-          <item name="Failover"            href="/manual/appenders.html@FailoverAppender"/>
-          <item name="File"                href="/manual/appenders.html#FileAppender"/>
-          <item name="Flume"               href="/manual/appenders.html#FlumeAvroAppender"/>
-          <item name="JMSQueue"            href="/manual/appenders.html#JMSQueueAppender"/>
-          <item name="JSMTopic"            href="/manual/appenders.html#JMSTopicAppender"/>
-          <item name="OutputStream"        href="/manual/appenders.html#OutputStreamAppender"/>
-          <item name="Rewrite"             href="/manual/appenders.html#RewriteAppender"/>
-          <item name="RollingFile"         href="/manual/appenders.html#RollingFileappender"/>
-          <item name="Routing"             href="/manual/appenders.html#RoutingAppender"/>
-          <item name="Socket"              href="/manual/appenders.html#SocketAppender"/>
-          <item name="Syslog"              href="/manual/appenders.html#SyslogAppender"/>
-        </item>
-        <item name="Layouts"               href="/manual/layouts.html" collapse="true">
-          <item name="HTML"                href="/manual/layouts.html#HTMLLayout"/>
-          <item name="Pattern"             href="/manual/layouts.html#PatternLayout"/>
-          <item name="RFC5424"             href="/manual/layouts.html#RFC5424Layout"/>
-          <item name="Serialized"          href="/manual/layouts.html#SerializedLayout"/>
-          <item name="Syslog"              href="/manual/layouts.html#SyslogLayout"/>
-          <item name="XML"                 href="/manual/layouts.html#XMLLayout"/>
-        </item>
-        <item name="Filters"               href="/manual/filters.html" collapse="true">
-          <item name="Burst"               href="/manual/filters.html#BurstFilter"/>
-          <item name="CompositeFilter"     href="/manual/filters.html#CompositeFilter"/>
-          <item name="DynamicThreshold"    href="/manual/filters.html#DynamicThresholdFilter"/>
-          <item name="Map"                 href="/manual/filters.html#MapFilter"/>
-          <item name="Marker"              href="/manual/filters.html#MarkerFilter"/>
-          <item name="Regex"               href="/manual/filters.html#RegexFilter"/>
-          <item name="StructuredData"      href="/manual/filters.html#StructuredDataFilter"/>
-          <item name="ThreadContextMap"    href="/manual/filters.html#ThreadContextMapFilter"/>
-          <item name="Threshold"           href="/manual/filters.html#ThresholdFilter"/>
-          <item name="Time"                href="/manual/filters.html#TimeFilter"/>
-        </item>
-        <item name="ThreadContext"         href="/manual/thread-context.html"/>
-        <item name="JMX"                   href="/manual/jmx.html"/>
-        <item name="Logging Separation"    href="/manual/logsep.html"/>
-        <item name="Extending Log4j"       href="/manual/extending.html" collapse="true">
-          <item name="LoggerContextFactory" href="/manual/extending.html#LoggerContextFactory"/>
-          <item name="ContextSelector"     href="/manual/extending.html#ContextSelector"/>
-          <item name="ConfigurationFactory" href="/manual/extending.html#ConfigurationFactory"/>
-          <item name="LoggerConfig"        href="/manual/extending.html#LoggerConfig"/>
-          <item name="Lookups"             href="/manual/extending.html#Lookups"/>
-          <item name="Filters"             href="/manual/extending.html#Filters"/>
-          <item name="Appenders"           href="/manual/extending.html#Appenders"/>
-          <item name="Layouts"             href="/manual/extending.html#Layouts"/>
-          <item name="PatternConverters"   href="/manual/extending.html#PatternConverters"/>
-          <item name="Custom Plugins"      href="/manual/extending.html#Custom"/>
-        </item>
+    <menu name="Log4j2 API" inherit="top">
+      <item name="Log4j2 API" href="log4j2-api/api.html"/>
+    </menu>
+    <menu name="Manual" inherit="top">
+      <item name="Introduction" href="/manual/index.html"/>
+      <item name="Architecture" href="/manual/architecture.html"/>
+      <item name="Configuration" href="/manual/configuration.html"/>
+      <item name="Plugins" href="/manual/plugins.html" collapse="true">
+        <item name="Core" href="/manual/plugins.html#Core"/>
+        <item name="Converters" href="/manual/plugins.html#Converters"/>
+        <item name="Lookups" href="/manual/plugins.html#Lookups"/>
+      </item>
+      <item name="Lookups" href="/manual/lookups.html" collapse="true">
+        <item name="ContextMap" href="/manual/lookups.html#ContextMapLookup"/>
+        <item name="StructuredData" href="/manual/lookups.html#StructuredDataLookup"/>
+        <item name="SystemProperties" href="/manual/lookups.html#SystemPropertiesLookup"/>
+      </item>
+      <item name="Appenders" href="/manual/appenders.html" collapse="true">
+        <item name="Console" href="/manual/appenders.html@ConsoleAppender"/>
+        <item name="Failover" href="/manual/appenders.html@FailoverAppender"/>
+        <item name="File" href="/manual/appenders.html#FileAppender"/>
+        <item name="Flume" href="/manual/appenders.html#FlumeAvroAppender"/>
+        <item name="JMSQueue" href="/manual/appenders.html#JMSQueueAppender"/>
+        <item name="JSMTopic" href="/manual/appenders.html#JMSTopicAppender"/>
+        <item name="OutputStream" href="/manual/appenders.html#OutputStreamAppender"/>
+        <item name="Rewrite" href="/manual/appenders.html#RewriteAppender"/>
+        <item name="RollingFile" href="/manual/appenders.html#RollingFileappender"/>
+        <item name="Routing" href="/manual/appenders.html#RoutingAppender"/>
+        <item name="Socket" href="/manual/appenders.html#SocketAppender"/>
+        <item name="Syslog" href="/manual/appenders.html#SyslogAppender"/>
+      </item>
+      <item name="Layouts" href="/manual/layouts.html" collapse="true">
+        <item name="HTML" href="/manual/layouts.html#HTMLLayout"/>
+        <item name="Pattern" href="/manual/layouts.html#PatternLayout"/>
+        <item name="RFC5424" href="/manual/layouts.html#RFC5424Layout"/>
+        <item name="Serialized" href="/manual/layouts.html#SerializedLayout"/>
+        <item name="Syslog" href="/manual/layouts.html#SyslogLayout"/>
+        <item name="XML" href="/manual/layouts.html#XMLLayout"/>
       </item>
-      <item name="Wiki"                    href="http://wiki.apache.org/logging"/>
+      <item name="Filters" href="/manual/filters.html" collapse="true">
+        <item name="Burst" href="/manual/filters.html#BurstFilter"/>
+        <item name="CompositeFilter" href="/manual/filters.html#CompositeFilter"/>
+        <item name="DynamicThreshold" href="/manual/filters.html#DynamicThresholdFilter"/>
+        <item name="Map" href="/manual/filters.html#MapFilter"/>
+        <item name="Marker" href="/manual/filters.html#MarkerFilter"/>
+        <item name="Regex" href="/manual/filters.html#RegexFilter"/>
+        <item name="StructuredData" href="/manual/filters.html#StructuredDataFilter"/>
+        <item name="ThreadContextMap" href="/manual/filters.html#ThreadContextMapFilter"/>
+        <item name="Threshold" href="/manual/filters.html#ThresholdFilter"/>
+        <item name="Time" href="/manual/filters.html#TimeFilter"/>
+      </item>
+      <item name="ThreadContext" href="/manual/thread-context.html"/>
+      <item name="JMX" href="/manual/jmx.html"/>
+      <item name="Logging Separation" href="/manual/logsep.html"/>
+      <item name="Extending Log4j" href="/manual/extending.html" collapse="true">
+        <item name="LoggerContextFactory" href="/manual/extending.html#LoggerContextFactory"/>
+        <item name="ContextSelector" href="/manual/extending.html#ContextSelector"/>
+        <item name="ConfigurationFactory" href="/manual/extending.html#ConfigurationFactory"/>
+        <item name="LoggerConfig" href="/manual/extending.html#LoggerConfig"/>
+        <item name="Lookups" href="/manual/extending.html#Lookups"/>
+        <item name="Filters" href="/manual/extending.html#Filters"/>
+        <item name="Appenders" href="/manual/extending.html#Appenders"/>
+        <item name="Layouts" href="/manual/extending.html#Layouts"/>
+        <item name="PatternConverters" href="/manual/extending.html#PatternConverters"/>
+        <item name="Custom Plugins" href="/manual/extending.html#Custom"/>
+      </item>
+    </menu>
+    <menu name="Logging Adapters" inherit="top">
+      <item name="Log4j 1.x API" href="log4j12-api/api.html"/>
+      <item name="Commons Logging" href="log4j2-jcl/api.html"/>
+      <item name="SLF4J" href="slf4j-impl/api.html"/>
+    </menu>
+    <menu name="Download and Build" inherit="top">
+      <item name="Download and Build" href="/download.html"/>
     </menu>
     <menu name="Components" inherit="top">
       <item name="API" href="log4j2-api/index.html"/>
@@ -106,7 +120,8 @@
       <item name="SLF4J Binding" href="slf4j-impl/index.html"/>
     </menu>
     <links>
-      <item name="Apache" href="http://www.apache.org/" />
+      <item name="Logging Wiki" href="http://wiki.apache.org/logging"/>
+      <item name="Apache" href="http://www.apache.org/"/>
       <item name="Logging Services" href="http://logging.apache.org/"/>
       <item name="Log4j" href="http://logging.apache.org/log4j/"/>
       <item name="Log4j Companions" href="http://logging.apache.org/log4j/companions"/>

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/lookups.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/lookups.xml?rev=1204693&r1=1204692&r2=1204693&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/lookups.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/src/site/xdoc/manual/lookups.xml Mon Nov 21 20:47:56 2011
@@ -24,6 +24,9 @@
 
     <body>
       <section name="Lookups">
+        <p>
+
+        </p>
         <a name="ContextMapLookup"/>
         <subsection name="ContextMapLookup">