logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1403143 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/test/java/org/apache/logging/log4j/ core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/ src/changes/
Date Mon, 29 Oct 2012 01:24:40 GMT
Author: rgoers
Date: Mon Oct 29 01:24:39 2012
New Revision: 1403143

URL: http://svn.apache.org/viewvc?rev=1403143&view=rev
Log:
LOG4J2-85 - Add ThreadContext.push(String format, Object... args)

Added:
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java?rev=1403143&r1=1403142&r2=1403143&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
Mon Oct 29 01:24:39 2012
@@ -17,6 +17,8 @@
 
 package org.apache.logging.log4j;
 
+import org.apache.logging.log4j.message.ParameterizedMessage;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -259,6 +261,27 @@ public final class ThreadContext {
         }
         stack.push(message);
     }
+    /**
+     * Push new diagnostic context information for the current thread.
+     * <p/>
+     * <p>The contents of the <code>message</code> and args parameters
are
+     * determined solely by the client. The message will be treated as a format String
+     * and tokens will be replaced with the String value of the arguments in accordance
+     * with ParameterizedMessage.
+     *
+     * @param message The new diagnostic context information.
+     */
+    public static void push(String message, Object... args) {
+        if (!useStack) {
+            return;
+        }
+        ContextStack stack = localStack.get();
+        if (stack == null) {
+            stack = new ThreadContextStack();
+            localStack.set(stack);
+        }
+        stack.push(ParameterizedMessage.format(message, args));
+    }
 
     /**
      * Remove the diagnostic context for this thread.

Added: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java?rev=1403143&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
(added)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/ThreadContextTest.java
Mon Oct 29 01:24:39 2012
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+public class ThreadContextTest {
+
+    @Test
+    public void testPush() {
+        ThreadContext.push("Hello");
+        ThreadContext.push("{} is {}", ThreadContextTest.class.getSimpleName(), "running");
+        assertEquals("Incorrect parameterized stack value", ThreadContext.pop(), "ThreadContextTest
is running");
+        assertEquals("Incorrect simple stack value", ThreadContext.pop(), "Hello");
+    }
+}

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java?rev=1403143&r1=1403142&r2=1403143&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/appender/rewrite/MapRewritePolicyTest.java
Mon Oct 29 01:24:39 2012
@@ -1,3 +1,19 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache license, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the license for the specific language governing permissions and
+* limitations under the license.
+*/
 package org.apache.logging.log4j.core.appender.rewrite;
 
 import java.util.HashMap;
@@ -7,7 +23,6 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.MarkerManager;
 import org.apache.logging.log4j.ThreadContext;
 import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.appender.rewrite.MapRewritePolicy;
 import org.apache.logging.log4j.core.helpers.KeyValuePair;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.ThrowableProxy;

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1403143&r1=1403142&r2=1403143&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Mon Oct 29 01:24:39 2012
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta3" date="TBD" description= "Bug fixes and enhancements">
+      <action issue="LOG4J2-85" dev="rgoers" type="update">
+        Add ThreadContext.push(String format, Object... args)
+      </action>
       <action issue="LOG4J2-103" dev="rgoers" type="fix" due-to="Das Archive">
         The LogEvent was wrapping a ThrowableProxy with another ThrowableProxy when deserializing.
       </action>



Mime
View raw message