logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r946745 [2/3] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: log4j12-api/ log4j12-api/src/main/java/org/apache/log4j/ log4j12-api/src/main/java/org/apache/logging/ log4j12-api/src/test/java/org/ log4j12-api/src/test/java/org/a...
Date Thu, 20 May 2010 18:27:55 GMT
Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/util/SerializationTestHelper.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/util/SerializationTestHelper.java?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/util/SerializationTestHelper.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/java/org/apache/log4j/util/SerializationTestHelper.java Thu May 20 18:27:54 2010
@@ -0,0 +1,158 @@
+/*
+ * 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.log4j.util;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.junit.Assert;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Utiities for serialization tests.
+ */
+public class SerializationTestHelper {
+    /**
+     * Private constructor.
+     */
+    private SerializationTestHelper() {
+    }
+
+    /**
+     * Creates a clone by serializing object and
+     * deserializing byte stream.
+     *
+     * @param obj object to serialize and deserialize.
+     * @return clone
+     * @throws IOException            on IO error.
+     * @throws ClassNotFoundException if class not found.
+     */
+    public static Object serializeClone(final Object obj)
+        throws IOException, ClassNotFoundException {
+        ByteArrayOutputStream memOut = new ByteArrayOutputStream();
+        ObjectOutputStream objOut = new ObjectOutputStream(memOut);
+        objOut.writeObject(obj);
+        objOut.close();
+
+        ByteArrayInputStream src = new ByteArrayInputStream(memOut.toByteArray());
+        ObjectInputStream objIs = new ObjectInputStream(src);
+
+        return objIs.readObject();
+    }
+
+    /**
+     * Deserializes a specified file.
+     *
+     * @param witness serialization file, may not be null.
+     * @return deserialized object.
+     * @throws Exception thrown on IO or deserialization exception.
+     */
+    public static Object deserializeStream(final String witness)
+        throws Exception {
+        FileInputStream fileIs = new FileInputStream(witness);
+        ObjectInputStream objIs = new ObjectInputStream(fileIs);
+
+        return objIs.readObject();
+    }
+
+    /**
+     * Checks the serialization of an object against an file
+     * containing the expected serialization.
+     *
+     * @param witness    name of file containing expected serialization.
+     * @param obj        object to be serialized.
+     * @param skip       positions in serialized stream that should not be compared.
+     * @param endCompare position to stop comparison.
+     * @throws Exception thrown on IO or serialization exception.
+     */
+    public static void assertSerializationEquals(
+        final String witness, final Object obj, final int[] skip,
+        final int endCompare) throws Exception {
+        ByteArrayOutputStream memOut = new ByteArrayOutputStream();
+        ObjectOutputStream objOut = new ObjectOutputStream(memOut);
+        objOut.writeObject(obj);
+        objOut.close();
+
+        assertStreamEquals(witness, memOut.toByteArray(), skip, endCompare);
+    }
+
+    /**
+     * Asserts the serialized form of an object.
+     *
+     * @param witness    file name of expected serialization.
+     * @param actual     byte array of actual serialization.
+     * @param skip       positions to skip comparison.
+     * @param endCompare position to stop comparison.
+     * @throws IOException thrown on IO or serialization exception.
+     */
+    public static void assertStreamEquals(
+        final String witness, final byte[] actual, final int[] skip,
+        final int endCompare) throws IOException {
+        File witnessFile = new File(witness);
+
+        if (witnessFile.exists()) {
+            int skipIndex = 0;
+            byte[] expected = new byte[actual.length];
+            FileInputStream is = new FileInputStream(witnessFile);
+            int bytesRead = is.read(expected);
+            is.close();
+
+            if (bytesRead < endCompare) {
+                assertEquals(bytesRead, actual.length);
+            }
+
+            int endScan = actual.length;
+
+            if (endScan > endCompare) {
+                endScan = endCompare;
+            }
+
+            for (int i = 0; i < endScan; i++) {
+                if ((skipIndex < skip.length) && (skip[skipIndex] == i)) {
+                    skipIndex++;
+                } else {
+                    if (expected[i] != actual[i]) {
+                        assertEquals(
+                            "Difference at offset " + i, expected[i], actual[i]);
+                    }
+                }
+            }
+        } else {
+            //
+            //  if the file doesn't exist then
+            //      assume that we are setting up and need to write it
+            FileOutputStream os = new FileOutputStream(witnessFile);
+            os.write(actual);
+            os.close();
+            fail("Writing witness file " + witness);
+        }
+    }
+}
+

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_en_US.properties
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_en_US.properties?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_en_US.properties (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_en_US.properties Thu May 20 18:27:54 2010
@@ -0,0 +1,17 @@
+# 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.
+test=This is the English, US test.
+hello_world=Hello world.
+msg1=This is test number {0} with string argument {1}.

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr.properties
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr.properties?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr.properties (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr.properties Thu May 20 18:27:54 2010
@@ -0,0 +1,17 @@
+# 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.
+test=Ceci est le test en francais pour la France.
+hello_world=Bonjour la France.
+msg1=Ceci est le test numero {0} contenant l''argument {1}.

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr_CH.properties
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr_CH.properties?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr_CH.properties (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/L7D_fr_CH.properties Thu May 20 18:27:54 2010
@@ -0,0 +1,16 @@
+# 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.
+test=Ceci est le test en francais pour la p'tite Suisse.
+hello world=Salut le monde.

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/witness/serialization/info.bin
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/witness/serialization/info.bin?rev=946745&view=auto
==============================================================================
Binary file - no diff available.

Propchange: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j12-api/src/test/resources/witness/serialization/info.bin
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.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/LocalizedMessage.java?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/LocalizedMessage.java Thu May 20 18:27:54 2010
@@ -0,0 +1,257 @@
+/*
+ * 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.message;
+
+import org.apache.logging.log4j.internal.StatusLogger;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ *
+ */
+public class LocalizedMessage extends ParameterizedMessage {
+
+    private String bundleId;
+
+    private transient ResourceBundle bundle;
+
+    private Locale locale;
+
+    private Map<MessageHint, String> hints = new HashMap<MessageHint, String>();
+
+    private StatusLogger logger = StatusLogger.getLogger();
+
+    public LocalizedMessage() {
+        super();
+        setup(null, null, null);
+    }
+
+    public LocalizedMessage(String messagePattern, String[] stringArgs, Throwable throwable) {
+        super(messagePattern, stringArgs, throwable);
+        setup(null, null, null);
+    }
+
+
+    public LocalizedMessage(String bundleId, String key, String[] stringArgs,
+                            Throwable throwable) {
+        super(key, stringArgs, throwable);
+        setup(bundleId, null, null);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, String key, String[] stringArgs,
+                            Throwable throwable) {
+        super(key, stringArgs, throwable);
+        setup(null, bundle, null);
+    }
+
+    public LocalizedMessage(String bundleId, Locale locale, String key, String[] stringArgs,
+                            Throwable throwable) {
+        super(key, stringArgs, throwable);
+        setup(bundleId, null, locale);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, String[] stringArgs,
+                            Throwable throwable) {
+        super(key, stringArgs, throwable);
+        setup(null, bundle, locale);
+    }
+
+    public LocalizedMessage(Locale locale, String key, String[] stringArgs, Throwable throwable) {
+        super(key, stringArgs, throwable);
+        setup(null, null, locale);
+    }
+
+
+    /**
+     * <p>This method returns a LocalizedMessage which contains the arguments converted to String
+     * as well as an optional Throwable.</p>
+     * <p/>
+     * <p>If the last argument is a Throwable and is NOT used up by a placeholder in the message
+     * pattern it is returned in LocalizedMessage.getThrowable() and won't be contained in the
+     * created String[].<br/>
+     * If it is used up ParameterizedMessage.getThrowable() will return null even if the last
+     * argument was a Throwable!</p>
+     *
+     * @param messagePattern the message pattern that to be checked for placeholders.
+     * @param arguments      the argument array to be converted.
+     * @return a LocalizedMessage containing the messagePattern, converted arguments and,
+     * optionally, a Throwable.
+     */
+    public LocalizedMessage(String messagePattern, Object[] arguments) {
+        super(messagePattern, arguments);
+        setup(null, null, null);
+    }
+
+    public LocalizedMessage(String bundleId, String key, Object[] arguments) {
+        super(key, arguments);
+        setup(bundleId, null, null);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, String key, Object[] arguments) {
+        super(key, arguments);
+        setup(null, bundle, null);
+    }
+
+    public LocalizedMessage(String bundleId, Locale locale, String key, Object[] arguments) {
+        super(key, arguments);
+        setup(bundleId, null, locale);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object[] arguments) {
+        super(key, arguments);
+        setup(null, bundle, locale);
+    }
+
+    public LocalizedMessage(Locale locale, String key, Object[] arguments) {
+        super(key, arguments);
+        setup(null, null, locale);
+    }
+
+    public LocalizedMessage(String messagePattern, Object arg) {
+        super(messagePattern, arg);
+        setup(null, null, null);
+    }
+
+    public LocalizedMessage(String bundleId, String key, Object arg) {
+        super(key, arg);
+        setup(bundleId, null, null);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, String key, Object arg) {
+        super(key, arg);
+        setup(null, bundle, null);
+    }
+
+    public LocalizedMessage(String bundleId, Locale locale, String key, Object arg) {
+        super(key, arg);
+        setup(bundleId, null, locale);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object arg) {
+        super(key, arg);
+        setup(null, bundle, locale);
+    }
+
+    public LocalizedMessage(Locale locale, String key, Object arg) {
+        super(key, arg);
+        setup(null, null, locale);
+    }
+
+    public LocalizedMessage(String messagePattern, Object arg1, Object arg2) {
+        super(messagePattern, arg1, arg2);
+        setup(null, null, null);
+    }
+
+    public LocalizedMessage(String bundleId, String key, Object arg1, Object arg2) {
+        super(key, arg1, arg2);
+        setup(bundleId, null, null);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, String key, Object arg1, Object arg2) {
+        super(key, arg1, arg2);
+        setup(null, bundle, null);
+    }
+
+    public LocalizedMessage(String bundleId, Locale locale, String key, Object arg1, Object arg2) {
+        super(key, arg1, arg2);
+        setup(bundleId, null, locale);
+    }
+
+    public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object arg1,
+                            Object arg2) {
+        super(key, arg1, arg2);
+        setup(null, bundle, locale);
+    }
+
+    public LocalizedMessage(Locale locale, String key, Object arg1, Object arg2) {
+        super(key, arg1, arg2);
+        setup(null, null, locale);
+    }
+
+    private void setup(String bundleId, ResourceBundle bundle, Locale locale) {
+        this.bundleId = bundleId;
+        this.bundle = bundle;
+        this.locale = locale;
+        hints.put(MessageHint.LOGGER_NAME, "");
+    }
+
+    @Override
+    public Map<MessageHint, String> getHints() {
+        return hints;
+    }
+
+    @Override
+    public String formatMessage(String messagePattern, String[] args) {
+        ResourceBundle bundle = this.bundle;
+        if (bundle == null) {
+            if (bundleId != null) {
+                bundle = getBundle(bundleId, locale, false);
+            } else {
+                String key = hints.get(MessageHint.LOGGER_NAME);
+                bundle = getBundle(key, locale, true);
+            }
+        }
+        String msgPattern = (bundle == null || !bundle.containsKey(messagePattern)) ?
+            messagePattern : bundle.getString(messagePattern);
+        return format(msgPattern, args);
+    }
+
+    /**
+     * Override this to use a ResourceBundle.Control in Java 6
+     * @param key The key to the bundle.
+     * @return The ResourceBundle.
+     */
+    protected ResourceBundle getBundle(String key, Locale locale, boolean loop) {
+        ResourceBundle rb = null;
+
+        if (key == null) {
+            return null;
+        }
+        try {
+            if (locale != null) {
+                rb = ResourceBundle.getBundle(key, locale);
+            } else {
+                rb = ResourceBundle.getBundle(key);
+            }
+        } catch (MissingResourceException ex) {
+            if (!loop) {
+                logger.debug("Unable to locate ResourceBundle " + key);
+                return null;
+            }
+        }
+
+        String substr = key;
+        int i;
+        while (rb == null && (i = substr.lastIndexOf(".")) > 0) {
+            substr = substr.substring(0, i);
+            try {
+                if (locale != null) {
+                    rb = ResourceBundle.getBundle(substr, locale);
+                } else {
+                    rb = ResourceBundle.getBundle(substr);
+                }
+            } catch (MissingResourceException ex) {
+                logger.debug("Unable to locate ResourceBundle " + substr);
+            }
+        }
+        return rb;
+    }
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.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/Message.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/Message.java Thu May 20 18:27:54 2010
@@ -17,26 +17,40 @@
 package org.apache.logging.log4j.message;
 
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * An interface for various Message implementations that can be logged.
  */
 public interface Message extends Serializable {
-  /**
-   * Returns the Message formatted as a String.
-   * @return The message String.
-   */
-  String getFormattedMessage();
-
-  /**
-   * Returns the format portion of the Message
-   * @return
-   */
-  String getMessageFormat();
-
-  /**
-   * Returns parameter values, if any.
-   * @return An array of parameter values or null.
-   */
-  Object[] getParameters();
+    /**
+     * Returns the Message formatted as a String.
+     *
+     * @return The message String.
+     */
+    String getFormattedMessage();
+
+    /**
+     * Returns the format portion of the Message
+     *
+     * @return
+     */
+    String getMessageFormat();
+
+    /**
+     * Returns parameter values, if any.
+     *
+     * @return An array of parameter values or null.
+     */
+    Object[] getParameters();
+
+
+    /**
+     * Returns a Map of data that the Message would like to aid in formatting. The
+     * Message will construct the map with the keys it is requesting the implementation to
+     * provide values for. The Message must be able to return a formatted message even if
+     * no hints are provided.
+     * @return The Message hints.
+     */
+    Map<MessageHint, String> getHints();
 }

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MessageHint.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/MessageHint.java?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MessageHint.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/MessageHint.java Thu May 20 18:27:54 2010
@@ -0,0 +1,8 @@
+package org.apache.logging.log4j.message;
+
+/**
+ *
+ */
+public enum MessageHint {
+    LOGGER_NAME, FORMAT
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.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/ObjectMessage.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java Thu May 20 18:27:54 2010
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * Handles messages that contain an Object.
@@ -44,6 +45,9 @@ public class ObjectMessage implements Me
         return new Object[]{obj};
     }
 
+    public Map<MessageHint, String> getHints() {
+        return null;
+    }
 
     public boolean equals(Object o) {
         if (this == o) {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.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/ParameterizedMessage.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/ParameterizedMessage.java Thu May 20 18:27:54 2010
@@ -29,481 +29,465 @@ import java.util.Set;
 /**
  * Handles messages that consist of a format string containing '{}' to represent each replaceable token, and
  * the parameters.
- *
+ * <p/>
  * This class was originally written for Lillith (http://mac.freshmeat.net/projects/lilith-viewer) by
  * Joern Huxhorn where it is licensed under the LGPL. It has been relicensed here with his permission
  * providing that this attribution remain.
  */
 public class ParameterizedMessage implements Message, Serializable {
-  private static final long serialVersionUID = -665975803997290697L;
+    private static final long serialVersionUID = -665975803997290697L;
 
-  private String messagePattern;
-  private String[] stringArgs;
-  private transient Object[] argArray;
-  private transient String formattedMessage;
-  private transient Throwable throwable;
-
-  public ParameterizedMessage() {
-    this(null, null, null);
-  }
-
-  public ParameterizedMessage(String messagePattern, String[] stringArgs, Throwable throwable) {
-    this.messagePattern = messagePattern;
-    this.stringArgs = stringArgs;
-    this.throwable = throwable;
-  }
-
-  /**
-   * <p>This method returns a ParameterizedMessage which contains the arguments converted to String
-   * as well as an optional Throwable.</p>
-   * <p/>
-   * <p>If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned
-   * in ParameterizedMessage.getThrowable() and won't be contained in the created String[].<br/>
-   * If it is used up ParameterizedMessage.getThrowable() will return null even if the last argument was a Throwable!</p>
-   *
-   * @param messagePattern the message pattern that to be checked for placeholders.
-   * @param arguments      the argument array to be converted.
-   * @return a ParameterizedMessage containing the messagePattern, converted arguments and, optionally, a Throwable.
-   */
-  public ParameterizedMessage(String messagePattern, Object[] arguments) {
-    this.messagePattern = messagePattern;
-    if (arguments == null) {
-      return;
-    }
-    parseArguments(arguments);
-  }
-
-  public ParameterizedMessage(String messagePattern, Object arg) {
-    this(messagePattern, new Object[] {arg});
-  }
-
-  public ParameterizedMessage(String messagePattern, Object arg1, Object arg2) {
-    this(messagePattern, new Object[] {arg1, arg2});
-  }
-
-  private void parseArguments(Object[] arguments) {
-    int argsCount = countArgumentPlaceholders(messagePattern);
-    int resultArgCount = arguments.length;
-    if (argsCount < arguments.length) {
-      if (arguments[arguments.length - 1] instanceof Throwable) {
-        throwable = (Throwable) arguments[arguments.length - 1];
-        resultArgCount--;
-      }
-    }
-    argArray = new Object[resultArgCount];
-    for (int i=0; i < resultArgCount; ++i) {
-      argArray[i] = arguments[i];
-    }
-
-    if (argsCount == 1 && throwable == null && arguments.length > 1) {
-      // special case
-      stringArgs = new String[1];
-      stringArgs[0] = deepToString(arguments);
-    }
-    else {
-      stringArgs = new String[resultArgCount];
-      for (int i = 0; i < stringArgs.length; i++) {
-        stringArgs[i] = deepToString(arguments[i]);
-      }
-    }
-  }
-
-  public String getFormattedMessage() {
-    if (formattedMessage == null) {
-      formatMessage();
-    }
-    return formattedMessage;
-  }
-
-  public String getMessageFormat() {
-    return messagePattern;
-  }
-
-  public void setMessageFormat(String messagePattern) {
-    this.messagePattern = messagePattern;
-    this.formattedMessage = null;
-  }
-
-  public Object[] getParameters() {
-    if (argArray != null) {
-      return argArray;
-    }
-    return stringArgs;
-  }
-
-  public void setParameters(String[] parameters) {
-    this.stringArgs = parameters;
-    this.formattedMessage = null;
-  }
-
-  public void setParameters(Object[] parameters) {
-    parseArguments(parameters);
-    this.formattedMessage = null;
-  }
-
-  public void setThrowable(Throwable throwable) {
-    this.throwable = throwable;
-  }
-
-  /**
-   * Returns the Throwable that was given as the last argument, if any.
-   * It will not survive serialization.
-   *
-   * @return the Throwable, if any.
-   */
-  public Throwable getThrowable() {
-    return throwable;
-  }
-
-  private void formatMessage() {
-    if (formattedMessage == null) {
-      formattedMessage = format(messagePattern, stringArgs);
-    }
-  }
-
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
-    ParameterizedMessage that = (ParameterizedMessage) o;
-
-    if (messagePattern != null ? !messagePattern.equals(that.messagePattern) : that.messagePattern != null) {
-      return false;
-    }
-    if (!Arrays.equals(stringArgs, that.stringArgs)) return false;
-    //if (throwable != null ? !throwable.equals(that.throwable) : that.throwable != null) return false;
-
-    return true;
-  }
-
-  public int hashCode() {
-    int result = messagePattern != null ? messagePattern.hashCode() : 0;
-    result = 31 * result + (stringArgs != null ? Arrays.hashCode(stringArgs) : 0);
-    return result;
-  }
-
-  private static final char DELIM_START = '{';
-  private static final char DELIM_STOP = '}';
-  private static final char ESCAPE_CHAR = '\\';
-
-  public static final String RECURSION_PREFIX = "[...";
-  public static final String RECURSION_SUFFIX = "...]";
-
-  public static final String ERROR_PREFIX = "[!!!";
-  public static final String ERROR_SEPARATOR = "=>";
-  public static final String ERROR_MSG_SEPARATOR = ":";
-  public static final String ERROR_SUFFIX = "!!!]";
-
-  /**
-   * Replace placeholders in the given messagePattern with arguments.
-   *
-   * @param messagePattern the message pattern containing placeholders.
-   * @param arguments      the arguments to be used to replace placeholders.
-   * @return the formatted message.
-   */
-  public static String format(String messagePattern, Object[] arguments) {
-    if (messagePattern == null || arguments == null || arguments.length == 0) {
-      return messagePattern;
-    }
-
-    StringBuilder result = new StringBuilder();
-    int escapeCounter = 0;
-    int currentArgument = 0;
-    for (int i = 0; i < messagePattern.length(); i++) {
-      char curChar = messagePattern.charAt(i);
-      if (curChar == ESCAPE_CHAR) {
-        escapeCounter++;
-      }
-      else {
-        if (curChar == DELIM_START) {
-          if (i < messagePattern.length() - 1) {
-            if (messagePattern.charAt(i + 1) == DELIM_STOP) {
-              // write escaped escape chars
-              int escapedEscapes = escapeCounter / 2;
-              for (int j = 0; j < escapedEscapes; j++) {
-                result.append(ESCAPE_CHAR);
-              }
-
-              if (escapeCounter % 2 == 1) {
-                // i.e. escaped
-                // write escaped escape chars
-                result.append(DELIM_START);
-                result.append(DELIM_STOP);
-              }
-              else {
-                // unescaped
-                if (currentArgument < arguments.length) {
-                  result.append(arguments[currentArgument]);
+    private String messagePattern;
+    private String[] stringArgs;
+    private transient Object[] argArray;
+    private transient String formattedMessage;
+    private transient Throwable throwable;
+
+    public ParameterizedMessage() {
+        this(null, null, null);
+    }
+
+    public ParameterizedMessage(String messagePattern, String[] stringArgs, Throwable throwable) {
+        this.messagePattern = messagePattern;
+        this.stringArgs = stringArgs;
+        this.throwable = throwable;
+    }
+
+    /**
+     * <p>This method returns a ParameterizedMessage which contains the arguments converted to String
+     * as well as an optional Throwable.</p>
+     * <p/>
+     * <p>If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned
+     * in ParameterizedMessage.getThrowable() and won't be contained in the created String[].<br/>
+     * If it is used up ParameterizedMessage.getThrowable() will return null even if the last argument was a Throwable!</p>
+     *
+     * @param messagePattern the message pattern that to be checked for placeholders.
+     * @param arguments      the argument array to be converted.
+     * @return a ParameterizedMessage containing the messagePattern, converted arguments and, optionally, a Throwable.
+     */
+    public ParameterizedMessage(String messagePattern, Object[] arguments) {
+        this.messagePattern = messagePattern;
+        if (arguments == null) {
+            return;
+        }
+        parseArguments(arguments);
+    }
+
+    public ParameterizedMessage(String messagePattern, Object arg) {
+        this(messagePattern, new Object[]{arg});
+    }
+
+    public ParameterizedMessage(String messagePattern, Object arg1, Object arg2) {
+        this(messagePattern, new Object[]{arg1, arg2});
+    }
+
+    public Map<MessageHint, String> getHints() {
+        return null;
+    }
+
+    private void parseArguments(Object[] arguments) {
+        int argsCount = countArgumentPlaceholders(messagePattern);
+        int resultArgCount = arguments.length;
+        if (argsCount < arguments.length) {
+            if (arguments[arguments.length - 1] instanceof Throwable) {
+                throwable = (Throwable) arguments[arguments.length - 1];
+                resultArgCount--;
+            }
+        }
+        argArray = new Object[resultArgCount];
+        for (int i = 0; i < resultArgCount; ++i) {
+            argArray[i] = arguments[i];
+        }
+
+        if (argsCount == 1 && throwable == null && arguments.length > 1) {
+            // special case
+            stringArgs = new String[1];
+            stringArgs[0] = deepToString(arguments);
+        } else {
+            stringArgs = new String[resultArgCount];
+            for (int i = 0; i < stringArgs.length; i++) {
+                stringArgs[i] = deepToString(arguments[i]);
+            }
+        }
+    }
+
+    public String getFormattedMessage() {
+        if (formattedMessage == null) {
+            formattedMessage = formatMessage(messagePattern, stringArgs);
+        }
+        return formattedMessage;
+    }
+
+    public String getMessageFormat() {
+        return messagePattern;
+    }
+
+    public void setMessageFormat(String messagePattern) {
+        this.messagePattern = messagePattern;
+        this.formattedMessage = null;
+    }
+
+    public Object[] getParameters() {
+        if (argArray != null) {
+            return argArray;
+        }
+        return stringArgs;
+    }
+
+    public void setParameters(String[] parameters) {
+        this.stringArgs = parameters;
+        this.formattedMessage = null;
+    }
+
+    public void setParameters(Object[] parameters) {
+        parseArguments(parameters);
+        this.formattedMessage = null;
+    }
+
+    public void setThrowable(Throwable throwable) {
+        this.throwable = throwable;
+    }
+
+    /**
+     * Returns the Throwable that was given as the last argument, if any.
+     * It will not survive serialization.
+     *
+     * @return the Throwable, if any.
+     */
+    public Throwable getThrowable() {
+        return throwable;
+    }
+
+    protected String formatMessage(String msgPattern, String[] sArgs) {
+        return format(msgPattern, sArgs);
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        ParameterizedMessage that = (ParameterizedMessage) o;
+
+        if (messagePattern != null ? !messagePattern.equals(that.messagePattern) : that.messagePattern != null) {
+            return false;
+        }
+        if (!Arrays.equals(stringArgs, that.stringArgs)) {
+            return false;
+        }
+        //if (throwable != null ? !throwable.equals(that.throwable) : that.throwable != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result = messagePattern != null ? messagePattern.hashCode() : 0;
+        result = 31 * result + (stringArgs != null ? Arrays.hashCode(stringArgs) : 0);
+        return result;
+    }
+
+    private static final char DELIM_START = '{';
+    private static final char DELIM_STOP = '}';
+    private static final char ESCAPE_CHAR = '\\';
+
+    public static final String RECURSION_PREFIX = "[...";
+    public static final String RECURSION_SUFFIX = "...]";
+
+    public static final String ERROR_PREFIX = "[!!!";
+    public static final String ERROR_SEPARATOR = "=>";
+    public static final String ERROR_MSG_SEPARATOR = ":";
+    public static final String ERROR_SUFFIX = "!!!]";
+
+    /**
+     * Replace placeholders in the given messagePattern with arguments.
+     *
+     * @param messagePattern the message pattern containing placeholders.
+     * @param arguments      the arguments to be used to replace placeholders.
+     * @return the formatted message.
+     */
+    public static String format(String messagePattern, Object[] arguments) {
+        if (messagePattern == null || arguments == null || arguments.length == 0) {
+            return messagePattern;
+        }
+
+        StringBuilder result = new StringBuilder();
+        int escapeCounter = 0;
+        int currentArgument = 0;
+        for (int i = 0; i < messagePattern.length(); i++) {
+            char curChar = messagePattern.charAt(i);
+            if (curChar == ESCAPE_CHAR) {
+                escapeCounter++;
+            } else {
+                if (curChar == DELIM_START) {
+                    if (i < messagePattern.length() - 1) {
+                        if (messagePattern.charAt(i + 1) == DELIM_STOP) {
+                            // write escaped escape chars
+                            int escapedEscapes = escapeCounter / 2;
+                            for (int j = 0; j < escapedEscapes; j++) {
+                                result.append(ESCAPE_CHAR);
+                            }
+
+                            if (escapeCounter % 2 == 1) {
+                                // i.e. escaped
+                                // write escaped escape chars
+                                result.append(DELIM_START);
+                                result.append(DELIM_STOP);
+                            } else {
+                                // unescaped
+                                if (currentArgument < arguments.length) {
+                                    result.append(arguments[currentArgument]);
+                                } else {
+                                    result.append(DELIM_START).append(DELIM_STOP);
+                                }
+                                currentArgument++;
+                            }
+                            i++;
+                            escapeCounter = 0;
+                            continue;
+                        }
+                    }
                 }
-                else {
-                  result.append(DELIM_START).append(DELIM_STOP);
+                // any other char beside ESCAPE or DELIM_START/STOP-combo
+                // write unescaped escape chars
+                if (escapeCounter > 0) {
+                    for (int j = 0; j < escapeCounter; j++) {
+                        result.append(ESCAPE_CHAR);
+                    }
+                    escapeCounter = 0;
                 }
-                currentArgument++;
-              }
-              i++;
-              escapeCounter = 0;
-              continue;
+                result.append(curChar);
             }
-          }
         }
-        // any other char beside ESCAPE or DELIM_START/STOP-combo
-        // write unescaped escape chars
-        if (escapeCounter > 0) {
-          for (int j = 0; j < escapeCounter; j++) {
-            result.append(ESCAPE_CHAR);
-          }
-          escapeCounter = 0;
-        }
-        result.append(curChar);
-      }
-    }
-    return result.toString();
-  }
-
-  /**
-   * Counts the number of unescaped placeholders in the given messagePattern.
-   *
-   * @param messagePattern the message pattern to be analyzed.
-   * @return the number of unescaped placeholders.
-   */
-  public static int countArgumentPlaceholders(String messagePattern) {
-    if (messagePattern == null) {
-      return 0;
-    }
-
-    int delim = messagePattern.indexOf(DELIM_START);
-
-    if (delim == -1) {
-      // special case, no placeholders at all.
-      return 0;
-    }
-    int result = 0;
-    boolean isEscaped = false;
-    for (int i = 0; i < messagePattern.length(); i++) {
-      char curChar = messagePattern.charAt(i);
-      if (curChar == ESCAPE_CHAR) {
-        isEscaped = !isEscaped;
-      }
-      else if (curChar == DELIM_START) {
-        if (!isEscaped) {
-          if (i < messagePattern.length() - 1) {
-            if (messagePattern.charAt(i + 1) == DELIM_STOP) {
-              result++;
-              i++;
+        return result.toString();
+    }
+
+    /**
+     * Counts the number of unescaped placeholders in the given messagePattern.
+     *
+     * @param messagePattern the message pattern to be analyzed.
+     * @return the number of unescaped placeholders.
+     */
+    public static int countArgumentPlaceholders(String messagePattern) {
+        if (messagePattern == null) {
+            return 0;
+        }
+
+        int delim = messagePattern.indexOf(DELIM_START);
+
+        if (delim == -1) {
+            // special case, no placeholders at all.
+            return 0;
+        }
+        int result = 0;
+        boolean isEscaped = false;
+        for (int i = 0; i < messagePattern.length(); i++) {
+            char curChar = messagePattern.charAt(i);
+            if (curChar == ESCAPE_CHAR) {
+                isEscaped = !isEscaped;
+            } else if (curChar == DELIM_START) {
+                if (!isEscaped) {
+                    if (i < messagePattern.length() - 1) {
+                        if (messagePattern.charAt(i + 1) == DELIM_STOP) {
+                            result++;
+                            i++;
+                        }
+                    }
+                }
+                isEscaped = false;
+            } else {
+                isEscaped = false;
             }
-          }
         }
-        isEscaped = false;
-      }
-      else {
-        isEscaped = false;
-      }
-    }
-    return result;
-  }
-
-  public static String deepToString(Object o) {
-    if (o == null) {
-      return null;
-    }
-    if (o instanceof String) {
-      return (String) o;
-    }
-    StringBuilder str = new StringBuilder();
-    Set dejaVu = new HashSet(); // that's actually a neat name ;)
-    recursiveDeepToString(o, str, dejaVu);
-    return str.toString();
-  }
-
-  /**
-   * This method performs a deep toString of the given Object.
-   * Primitive arrays are converted using their respective Arrays.toString methods while
-   * special handling is implemented for "container types", i.e. Object[], Map and Collection because those could
-   * contain themselves.
-   * <p/>
-   * dejaVu is used in case of those container types to prevent an endless recursion.
-   * <p/>
-   * It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior.
-   * They only check if the container is directly contained in itself, but not if a contained container contains the
-   * original one. Because of that, Arrays.toString(Object[]) isn't safe either.
-   * Confusing? Just read the last paragraph again and check the respective toString() implementation.
-   * <p/>
-   * This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o)
-   * would produce a relatively hard-to-debug StackOverflowError.
-   *
-   * @param o      the Object to convert into a String
-   * @param str    the StringBuilder that o will be appended to
-   * @param dejaVu a list of container identities that were already used.
-   */
-  private static void recursiveDeepToString(Object o, StringBuilder str, Set dejaVu) {
-    if (o == null) {
-      str.append("null");
-      return;
-    }
-    if (o instanceof String) {
-      str.append(o);
-      return;
-    }
-
-    Class oClass = o.getClass();
-    if (oClass.isArray()) {
-      if (oClass == byte[].class) {
-        str.append(Arrays.toString((byte[]) o));
-      }
-      else if (oClass == short[].class) {
-        str.append(Arrays.toString((short[]) o));
-      }
-      else if (oClass == int[].class) {
-        str.append(Arrays.toString((int[]) o));
-      }
-      else if (oClass == long[].class) {
-        str.append(Arrays.toString((long[]) o));
-      }
-      else if (oClass == float[].class) {
-        str.append(Arrays.toString((float[]) o));
-      }
-      else if (oClass == double[].class) {
-        str.append(Arrays.toString((double[]) o));
-      }
-      else if (oClass == boolean[].class) {
-        str.append(Arrays.toString((boolean[]) o));
-      }
-      else if (oClass == char[].class) {
-        str.append(Arrays.toString((char[]) o));
-      }
-      else {
-        // special handling of container Object[]
-        String id = identityToString(o);
-        if (dejaVu.contains(id)) {
-          str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
-        }
-        else {
-          dejaVu.add(id);
-          Object[] oArray = (Object[]) o;
-          str.append("[");
-          boolean first = true;
-          for (int i = 0; i < oArray.length; ++i) {
-            Object current = oArray[i];
-            if (first) {
-              first = false;
+        return result;
+    }
+
+    public static String deepToString(Object o) {
+        if (o == null) {
+            return null;
+        }
+        if (o instanceof String) {
+            return (String) o;
+        }
+        StringBuilder str = new StringBuilder();
+        Set dejaVu = new HashSet(); // that's actually a neat name ;)
+        recursiveDeepToString(o, str, dejaVu);
+        return str.toString();
+    }
+
+    /**
+     * This method performs a deep toString of the given Object.
+     * Primitive arrays are converted using their respective Arrays.toString methods while
+     * special handling is implemented for "container types", i.e. Object[], Map and Collection because those could
+     * contain themselves.
+     * <p/>
+     * dejaVu is used in case of those container types to prevent an endless recursion.
+     * <p/>
+     * It should be noted that neither AbstractMap.toString() nor AbstractCollection.toString() implement such a behavior.
+     * They only check if the container is directly contained in itself, but not if a contained container contains the
+     * original one. Because of that, Arrays.toString(Object[]) isn't safe either.
+     * Confusing? Just read the last paragraph again and check the respective toString() implementation.
+     * <p/>
+     * This means, in effect, that logging would produce a usable output even if an ordinary System.out.println(o)
+     * would produce a relatively hard-to-debug StackOverflowError.
+     *
+     * @param o      the Object to convert into a String
+     * @param str    the StringBuilder that o will be appended to
+     * @param dejaVu a list of container identities that were already used.
+     */
+    private static void recursiveDeepToString(Object o, StringBuilder str, Set dejaVu) {
+        if (o == null) {
+            str.append("null");
+            return;
+        }
+        if (o instanceof String) {
+            str.append(o);
+            return;
+        }
+
+        Class oClass = o.getClass();
+        if (oClass.isArray()) {
+            if (oClass == byte[].class) {
+                str.append(Arrays.toString((byte[]) o));
+            } else if (oClass == short[].class) {
+                str.append(Arrays.toString((short[]) o));
+            } else if (oClass == int[].class) {
+                str.append(Arrays.toString((int[]) o));
+            } else if (oClass == long[].class) {
+                str.append(Arrays.toString((long[]) o));
+            } else if (oClass == float[].class) {
+                str.append(Arrays.toString((float[]) o));
+            } else if (oClass == double[].class) {
+                str.append(Arrays.toString((double[]) o));
+            } else if (oClass == boolean[].class) {
+                str.append(Arrays.toString((boolean[]) o));
+            } else if (oClass == char[].class) {
+                str.append(Arrays.toString((char[]) o));
+            } else {
+                // special handling of container Object[]
+                String id = identityToString(o);
+                if (dejaVu.contains(id)) {
+                    str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
+                } else {
+                    dejaVu.add(id);
+                    Object[] oArray = (Object[]) o;
+                    str.append("[");
+                    boolean first = true;
+                    for (int i = 0; i < oArray.length; ++i) {
+                        Object current = oArray[i];
+                        if (first) {
+                            first = false;
+                        } else {
+                            str.append(", ");
+                        }
+                        recursiveDeepToString(current, str, new HashSet(dejaVu));
+                    }
+                    str.append("]");
+                }
+                //str.append(Arrays.deepToString((Object[]) o));
+            }
+        } else if (o instanceof Map) {
+            // special handling of container Map
+            String id = identityToString(o);
+            if (dejaVu.contains(id)) {
+                str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
+            } else {
+                dejaVu.add(id);
+                Map oMap = (Map) o;
+                str.append("{");
+                boolean isFirst = true;
+                Iterator iter = oMap.entrySet().iterator();
+                while (iter.hasNext()) {
+                    Map.Entry current = (Map.Entry) iter.next();
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    Object key = current.getKey();
+                    Object value = current.getValue();
+                    recursiveDeepToString(key, str, new HashSet(dejaVu));
+                    str.append("=");
+                    recursiveDeepToString(value, str, new HashSet(dejaVu));
+                }
+                str.append("}");
+            }
+        } else if (o instanceof Collection) {
+            // special handling of container Collection
+            String id = identityToString(o);
+            if (dejaVu.contains(id)) {
+                str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
+            } else {
+                dejaVu.add(id);
+                Collection oCol = (Collection) o;
+                str.append("[");
+                boolean isFirst = true;
+                Iterator iter = oCol.iterator();
+                while (iter.hasNext()) {
+                    Object current = iter.next();
+                    if (isFirst) {
+                        isFirst = false;
+                    } else {
+                        str.append(", ");
+                    }
+                    recursiveDeepToString(current, str, new HashSet(dejaVu));
+                }
+                str.append("]");
             }
-            else {
-              str.append(", ");
+        } else if (o instanceof Date) {
+            Date date = (Date) o;
+            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+            // I'll leave it like this for the moment... this could probably be optimized using ThreadLocal...
+            str.append(format.format(date));
+        } else {
+            // it's just some other Object, we can only use toString().
+            try {
+                str.append(o.toString());
             }
-            recursiveDeepToString(current, str, new HashSet(dejaVu));
-          }
-          str.append("]");
-        }
-        //str.append(Arrays.deepToString((Object[]) o));
-      }
-    }
-    else if (o instanceof Map) {
-      // special handling of container Map
-      String id = identityToString(o);
-      if (dejaVu.contains(id)) {
-        str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
-      }
-      else {
-        dejaVu.add(id);
-        Map oMap = (Map) o;
-        str.append("{");
-        boolean isFirst = true;
-        Iterator iter = oMap.entrySet().iterator();
-        while (iter.hasNext()) {
-          Map.Entry current = (Map.Entry) iter.next();
-          if (isFirst) {
-            isFirst = false;
-          }
-          else {
-            str.append(", ");
-          }
-          Object key = current.getKey();
-          Object value = current.getValue();
-          recursiveDeepToString(key, str, new HashSet(dejaVu));
-          str.append("=");
-          recursiveDeepToString(value, str, new HashSet(dejaVu));
-        }
-        str.append("}");
-      }
-    }
-    else if (o instanceof Collection) {
-      // special handling of container Collection
-      String id = identityToString(o);
-      if (dejaVu.contains(id)) {
-        str.append(RECURSION_PREFIX).append(id).append(RECURSION_SUFFIX);
-      }
-      else {
-        dejaVu.add(id);
-        Collection oCol = (Collection) o;
-        str.append("[");
-        boolean isFirst = true;
-        Iterator iter = oCol.iterator();
-        while (iter.hasNext()) {
-          Object current = iter.next();
-          if (isFirst) {
-            isFirst = false;
-          }
-          else {
-            str.append(", ");
-          }
-          recursiveDeepToString(current, str, new HashSet(dejaVu));
-        }
-        str.append("]");
-      }
-    }
-    else if (o instanceof Date) {
-      Date date = (Date) o;
-      SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-      // I'll leave it like this for the moment... this could probably be optimized using ThreadLocal...
-      str.append(format.format(date));
-    }
-    else {
-      // it's just some other Object, we can only use toString().
-      try {
-        str.append(o.toString());
-      }
-      catch (Throwable t) {
-        str.append(ERROR_PREFIX);
-        str.append(identityToString(o));
-        str.append(ERROR_SEPARATOR);
-        String msg = t.getMessage();
-        String className = t.getClass().getName();
-        str.append(className);
-        if (!className.equals(msg)) {
-          str.append(ERROR_MSG_SEPARATOR);
-          str.append(msg);
-        }
-        str.append(ERROR_SUFFIX);
-      }
-    }
-  }
-
-  /**
-   * This method returns the same as if Object.toString() would not have been
-   * overridden in obj.
-   * <p/>
-   * Note that this isn't 100% secure as collisions can always happen with hash codes.
-   * <p/>
-   * Copied from Object.hashCode():
-   * As much as is reasonably practical, the hashCode method defined by
-   * class <tt>Object</tt> does return distinct integers for distinct
-   * objects. (This is typically implemented by converting the internal
-   * address of the object into an integer, but this implementation
-   * technique is not required by the
-   * Java<font size="-2"><sup>TM</sup></font> programming language.)
-   *
-   * @param obj the Object that is to be converted into an identity string.
-   * @return the identity string as also defined in Object.toString()
-   */
-  public static String identityToString(Object obj) {
-    if (obj == null) {
-      return null;
-    }
-    return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
-  }
-
-  public String toString() {
-    return "ParameterizedMessage[messagePattern=" + messagePattern + ", stringArgs=" +
-        Arrays.toString(stringArgs) + ", throwable=" + throwable + "]";
-  }
+            catch (Throwable t) {
+                str.append(ERROR_PREFIX);
+                str.append(identityToString(o));
+                str.append(ERROR_SEPARATOR);
+                String msg = t.getMessage();
+                String className = t.getClass().getName();
+                str.append(className);
+                if (!className.equals(msg)) {
+                    str.append(ERROR_MSG_SEPARATOR);
+                    str.append(msg);
+                }
+                str.append(ERROR_SUFFIX);
+            }
+        }
+    }
+
+    /**
+     * This method returns the same as if Object.toString() would not have been
+     * overridden in obj.
+     * <p/>
+     * Note that this isn't 100% secure as collisions can always happen with hash codes.
+     * <p/>
+     * Copied from Object.hashCode():
+     * As much as is reasonably practical, the hashCode method defined by
+     * class <tt>Object</tt> does return distinct integers for distinct
+     * objects. (This is typically implemented by converting the internal
+     * address of the object into an integer, but this implementation
+     * technique is not required by the
+     * Java<font size="-2"><sup>TM</sup></font> programming language.)
+     *
+     * @param obj the Object that is to be converted into an identity string.
+     * @return the identity string as also defined in Object.toString()
+     */
+    public static String identityToString(Object obj) {
+        if (obj == null) {
+            return null;
+        }
+        return obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
+    }
+
+    public String toString() {
+        return "ParameterizedMessage[messagePattern=" + messagePattern + ", stringArgs=" +
+            Arrays.toString(stringArgs) + ", throwable=" + throwable + "]";
+    }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.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/SimpleMessage.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/message/SimpleMessage.java Thu May 20 18:27:54 2010
@@ -17,49 +17,58 @@
 package org.apache.logging.log4j.message;
 
 import java.io.Serializable;
+import java.util.Map;
 
 /**
  * The simplest possible implementation of Message. It just returns the String given as the constructor argument.
  */
 public class SimpleMessage implements Message, Serializable {
-  private static final long serialVersionUID = -8398002534962715992L;
+    private static final long serialVersionUID = -8398002534962715992L;
 
-  private final String message;
+    private final String message;
 
-  public SimpleMessage() {
-    this(null);
-  }
-
-  public SimpleMessage(String message) {
-    this.message = message;
-  }
-
-  public String getFormattedMessage() {
-    return message;
-  }
-
-  public String getMessageFormat() {
-    return message;
-  }
-
-  public Object[] getParameters() {
-    return null;
-  }
-
-  public boolean equals(Object o) {
-    if (this == o) return true;
-    if (o == null || getClass() != o.getClass()) return false;
-
-    SimpleMessage that = (SimpleMessage) o;
-
-    return !(message != null ? !message.equals(that.message) : that.message != null);
-  }
-
-  public int hashCode() {
-    return message != null ? message.hashCode() : 0;
-  }
-
-  public String toString() {
-    return "SimpleMessage[message=" + message + "]";
-  }
+    public SimpleMessage() {
+        this(null);
+    }
+
+    public SimpleMessage(String message) {
+        this.message = message;
+    }
+
+    public Map<MessageHint, String> getHints() {
+        return null;
+    }
+
+    public String getFormattedMessage() {
+        return message;
+    }
+
+    public String getMessageFormat() {
+        return message;
+    }
+
+    public Object[] getParameters() {
+        return null;
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+
+        SimpleMessage that = (SimpleMessage) o;
+
+        return !(message != null ? !message.equals(that.message) : that.message != null);
+    }
+
+    public int hashCode() {
+        return message != null ? message.hashCode() : 0;
+    }
+
+    public String toString() {
+        return "SimpleMessage[message=" + message + "]";
+    }
 }

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=946745&r1=946744&r2=946745&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 Thu May 20 18:27:54 2010
@@ -38,22 +38,30 @@ public class StructuredDataMessage imple
 
     private String type;
 
+    private Map<MessageHint, String> hints = new HashMap<MessageHint, String>();
+
     public StructuredDataMessage(final String id, final String msg, final String type) {
         this.id = new StructuredDataId(id, null, null);
         this.message = msg;
         this.type = type;
+        hints.put(MessageHint.FORMAT, "");
     }
 
     public StructuredDataMessage(final StructuredDataId id, final String msg, final String type) {
         this.id = id;
         this.message = msg;
         this.type = type;
+        hints.put(MessageHint.FORMAT, "");
     }
 
     protected StructuredDataMessage() {
 
     }
 
+    public Map<MessageHint, String> getHints() {
+        return hints;   
+    }
+
     public StructuredDataId getId() {
         return id;
     }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/main/java/org/apache/logging/log4j/spi/LoggerContext.java Thu May 20 18:27:54 2010
@@ -8,4 +8,6 @@ import org.apache.logging.log4j.Logger;
 public interface LoggerContext {
 
     Logger getLogger(String name);
+
+    boolean hasLogger(String name);
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-api/src/test/java/org/apache/logging/log4j/SimpleLoggerContext.java Thu May 20 18:27:54 2010
@@ -27,4 +27,8 @@ public class SimpleLoggerContext impleme
     public Logger getLogger(String name) {
         return logger;
     }
+
+    public boolean hasLogger(String name) {
+        return false;
+    }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/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/Log4jLogEvent.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Log4jLogEvent.java Thu May 20 18:27:54 2010
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.MDC;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.NDC;
 import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.MessageHint;
 
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
@@ -67,7 +68,10 @@ public class Log4jLogEvent implements Lo
         this.timestamp = timestamp;
         this.threadName = threadName;
         this.location = location;
-
+        Map<MessageHint, String> hints = message.getHints();
+        if (hints != null && hints.containsKey(MessageHint.LOGGER_NAME)) {
+            hints.put(MessageHint.LOGGER_NAME, name);
+        }
     }
 
     public Level getLevel() {

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.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/Logger.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/Logger.java Thu May 20 18:27:54 2010
@@ -31,7 +31,7 @@ import java.util.Map;
  *
  */
 public class Logger extends AbstractLogger {
-    private static String FQCN = Logger.class.getName();
+    //private static String FQCN = Logger.class.getName();
     private final String name;
 
     private final LoggerContext context;
@@ -39,7 +39,7 @@ public class Logger extends AbstractLogg
     /**
      * config should be consistent across threads.
      */
-    private volatile PrivateConfig config;
+    protected volatile PrivateConfig config;
 
     protected Logger(LoggerContext context, String name) {
         this.context = context;
@@ -51,6 +51,21 @@ public class Logger extends AbstractLogg
         return name;
     }
 
+    /**
+     * Return the parent of this Logger. If it doesn't already exist return a temporary Logger.
+     * @return The parent Logger.
+     */
+    public Logger getParent() {
+        LoggerConfig lc = config.loggerConfig.getParent();
+        if (lc == null) {
+            return null;
+        }
+        if (context.hasLogger(lc.getName())) {
+            return context.getLogger(name);
+        }
+        return new Logger(context, name);
+    }
+
     /* @Override
     protected String getFQCN() {
         return FQCN;
@@ -116,7 +131,7 @@ public class Logger extends AbstractLogg
     }
 
     public void addAppender(Appender appender) {
-        config.config.addLoggerAppender(name, appender);
+        config.config.addLoggerAppender(this, appender);
     }
 
     public void removeAppender(Appender appender) {
@@ -131,6 +146,18 @@ public class Logger extends AbstractLogg
         return config.loggerConfig.getFilters();
     }
 
+    public void addFilter(Filter filter) {
+        config.config.addLoggerFilter(this, filter);
+    }
+
+    public boolean isAdditive() {
+        return config.loggerConfig.isAdditive();
+    }
+
+    public void setAdditive(boolean additive) {
+        config.config.setLoggerAdditive(this, additive);
+    }
+
     /**
      * This method isn't synchronized to serialized updates to config. Rather, by doing this
      * it is guaranteed that all threads will see the update without having to declare the variable
@@ -142,12 +169,12 @@ public class Logger extends AbstractLogg
         this.config = new PrivateConfig(config, this);
     }
 
-    private class PrivateConfig {
-        private final LoggerConfig loggerConfig;
-        private final Configuration config;
-        private Level level;
-        private int intLevel;
-        private final Logger logger;
+    protected class PrivateConfig {
+        public final LoggerConfig loggerConfig;
+        public final Configuration config;
+        public Level level;
+        public int intLevel;
+        public final Logger logger;
 
         public PrivateConfig(Configuration config, Logger logger) {
             this.config = config;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.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/LoggerContext.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java Thu May 20 18:27:54 2010
@@ -36,21 +36,31 @@ public class LoggerContext implements or
 
     private static StatusLogger logger = StatusLogger.getLogger();
 
+    private static final LoggerFactory FACTORY = new Factory();
+
     public LoggerContext() {
         reconfigure();
     }
 
     public Logger getLogger(String name) {
+        return getLogger(FACTORY, name);
+    }
+
+    public Logger getLogger(LoggerFactory factory, String name) {
         Logger logger = loggers.get(name);
         if (logger != null) {
             return logger;
         }
 
-        logger = new Logger(this, name);
+        logger = factory.newInstance(this, name);
         Logger prev = loggers.putIfAbsent(name, logger);
         return prev == null ? logger : prev;
     }
 
+    public boolean hasLogger(String name) {
+        return loggers.containsKey(name);
+    }
+
     public Configuration getConfiguration() {
         return config;
     }
@@ -74,14 +84,23 @@ public class LoggerContext implements or
         Configuration config = ConfigurationFactory.getInstance().getConfiguration();
         config.start();
         Configuration old = setConfiguration(config);
-        for (Logger logger : loggers.values()) {
-            logger.updateConfiguration(config);
-        }
+        updateLoggers();
         if (old != null) {
             old.stop();
         }
         logger.debug("Reconfiguration completed");
     }
 
+    public void updateLoggers() {
+        for (Logger logger : loggers.values()) {
+            logger.updateConfiguration(config);
+        }
+    }
 
+    private static class Factory implements LoggerFactory {
+
+        public Logger newInstance(LoggerContext ctx, String name) {
+            return new Logger(ctx, name);
+        }
+    }
 }

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerFactory.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/LoggerFactory.java?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerFactory.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/LoggerFactory.java Thu May 20 18:27:54 2010
@@ -0,0 +1,9 @@
+package org.apache.logging.log4j.core;
+
+/**
+ *
+ */
+public interface LoggerFactory {
+
+    Logger newInstance(LoggerContext ctx, String name);
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderBase.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/AppenderBase.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderBase.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderBase.java Thu May 20 18:27:54 2010
@@ -45,8 +45,11 @@ public abstract class AppenderBase imple
 
     protected ErrorHandler handler;
 
-    public AppenderBase(String name) {
+    public static final String NAME = "name";    
+
+    public AppenderBase(String name, Layout layout) {
         this.name = name;
+        this.layout = layout;
     }
 
     public ErrorHandler getHandler() {
@@ -82,6 +85,9 @@ public abstract class AppenderBase imple
     }
 
     public void setLayout(Layout layout) {
+        if (layout == null) {
+            handler.error("The layout for appender " + getName() + " cannot be set to null");
+        }
         this.layout = layout;
     }
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.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/FileAppender.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/FileAppender.java Thu May 20 18:27:54 2010
@@ -34,7 +34,6 @@ public class FileAppender extends Output
 
     public static final String FILE_NAME = "fileName";
     public static final String APPEND = "append";
-    public static final String NAME = "name";
     public final String fileName;
 
     public FileAppender(String name, Layout layout, OutputStream os, String filename) {

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.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/ListAppender.java?rev=946745&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ListAppender.java Thu May 20 18:27:54 2010
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.apache.logging.log4j.core.LogEvent;
+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.PluginFactory;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+/**
+ *
+ */
+ @Plugin(name="List",type="Core")
+public class ListAppender extends AppenderBase {
+
+    private List<LogEvent> events = new ArrayList<LogEvent>();
+
+    public ListAppender(String name) {
+        super(name, null);
+    }
+
+    public synchronized void append(LogEvent event) {
+        events.add(event);
+    }
+
+    public synchronized void clear() {
+        events.clear();
+    }
+
+    public synchronized List<LogEvent> getEvents() {
+        return Collections.unmodifiableList(events);
+    }
+
+    @PluginFactory
+    public static ListAppender createAppender(Node node) {
+        String name = null;
+        for (Map.Entry<String, String> attr : node.getAttributes().entrySet()) {
+            if (attr.getKey().equalsIgnoreCase(NAME)) {
+                name = attr.getValue();
+            }
+        }
+
+        if (name == null) {
+            logger.error("No name provided for Appender of type " + node.getName());
+            return null;
+        }
+
+        return new ListAppender(name);
+    }
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamAppender.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/OutputStreamAppender.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamAppender.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/OutputStreamAppender.java Thu May 20 18:27:54 2010
@@ -63,8 +63,7 @@ public abstract class OutputStreamAppend
      * @param os The OutputStream.
      */
     public OutputStreamAppender(String name, Layout layout, OutputStream os) {
-        super(name);
-        this.layout = layout;
+        super(name, layout);
         this.setOutputStream(os);
     }
 
@@ -94,14 +93,6 @@ public abstract class OutputStreamAppend
     }
 
     @Override
-    public void setLayout(Layout layout) {
-        if (layout == null) {
-            handler.error("The layout for appender " + getName() + " cannot be set to null");
-        }
-        super.setLayout(layout);
-    }
-
-    @Override
     public void start() {
         if (this.layout == null) {
             logger.error("No layout set for the appender named [" + getName() + "].");

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=946745&r1=946744&r2=946745&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 Thu May 20 18:27:54 2010
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.config.plugins.PluginManager;
 import org.apache.logging.log4j.core.config.plugins.PluginType;
+import org.apache.logging.log4j.core.helpers.NameUtil;
 import org.apache.logging.log4j.internal.StatusLogger;
 
 import java.lang.reflect.Method;
@@ -92,7 +93,7 @@ public class BaseConfiguration implement
         }
     }
 
-    protected void setup() {        
+    protected void setup() {
     }
 
     protected void doConfigure() {
@@ -151,7 +152,8 @@ public class BaseConfiguration implement
         appenders.put(appender.getName(), appender);
     }
 
-    public void addLoggerAppender(String name, Appender appender) {
+    public void addLoggerAppender(org.apache.logging.log4j.core.Logger logger, Appender appender) {
+        String name = logger.getName();
         LoggerConfig lc = getLoggerConfig(name);
         if (lc.getName().equals(name)) {
             lc.addAppender(appender);
@@ -161,6 +163,36 @@ public class BaseConfiguration implement
             nlc.setParent(lc);
             loggers.putIfAbsent(name, nlc);
             setParents();
+            logger.getContext().updateLoggers();
+        }
+    }
+
+    public void addLoggerFilter(org.apache.logging.log4j.core.Logger logger, Filter filter) {
+        String name = logger.getName();
+        LoggerConfig lc = getLoggerConfig(name);
+        if (lc.getName().equals(name)) {
+            lc.addFilter(filter);
+        } else {
+            LoggerConfig nlc = new LoggerConfig(name, lc.getLevel(), lc.isAdditive());
+            nlc.addFilter(filter);
+            nlc.setParent(lc);
+            loggers.putIfAbsent(name, nlc);
+            setParents();
+            logger.getContext().updateLoggers();
+        }
+    }
+
+    public void setLoggerAdditive(org.apache.logging.log4j.core.Logger logger, boolean additive) {
+        String name = logger.getName();
+        LoggerConfig lc = getLoggerConfig(name);
+        if (lc.getName().equals(name)) {
+            lc.setAdditive(additive);
+        } else {
+            LoggerConfig nlc = new LoggerConfig(name, lc.getLevel(), additive);
+            nlc.setParent(lc);
+            loggers.putIfAbsent(name, nlc);
+            setParents();
+            logger.getContext().updateLoggers();
         }
     }
 
@@ -181,8 +213,7 @@ public class BaseConfiguration implement
         }
         int i = 0;
         String substr = name;
-        while ((i = substr.lastIndexOf(".")) > 0) {
-            substr = name.substring(0, i);
+        while ((substr = NameUtil.getSubName(substr)) != null) {
             if (loggers.containsKey(substr)) {
                 return loggers.get(substr);
             }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.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/Configuration.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java Thu May 20 18:27:54 2010
@@ -2,6 +2,7 @@ package org.apache.logging.log4j.core.co
 
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Logger;
 
 import java.util.Iterator;
 import java.util.List;
@@ -26,7 +27,11 @@ public interface Configuration {
 
     Map<String, LoggerConfig> getLoggers();
 
-    void addLoggerAppender(String name, Appender appender);    
+    void addLoggerAppender(Logger logger, Appender appender);
+
+    void addLoggerFilter(Logger logger, Filter filter);
+
+    void setLoggerAdditive(Logger logger, boolean additive);
 
     void start();
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.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/LoggerConfig.java?rev=946745&r1=946744&r2=946745&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java Thu May 20 18:27:54 2010
@@ -76,7 +76,7 @@ public class LoggerConfig implements Log
 
     protected LoggerConfig(String name, List<String> appenders, Filter[] filters, Level level,
                            boolean additive) {
-        this.logEventFactory = this;        
+        this.logEventFactory = this;
         this.name = name;
         this.appenderRefs = appenders;
         if (filters != null && filters.length > 0) {
@@ -95,6 +95,10 @@ public class LoggerConfig implements Log
         this.parent = parent;
     }
 
+    public LoggerConfig getParent() {
+        return this.parent;
+    }
+
     public void addAppender(Appender appender) {
         appenders.put(appender.getName(), new AppenderControl(appender));
     }
@@ -153,6 +157,10 @@ public class LoggerConfig implements Log
         return additive;
     }
 
+    public void setAdditive(boolean additive) {
+        this.additive = additive;
+    }
+
     public void log(String loggerName, Marker marker, String fqcn, Level level, Message data, Throwable t) {
         LogEvent event = logEventFactory.createEvent(loggerName, marker, fqcn, level, data, t);
         log(event);



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message