logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1084027 [2/2] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: ./ log4j2-core/ log4j2-core/output/ log4j2-core/src/main/java/org/apache/logging/log4j/core/ log4j2-core/src/main/java/org/apache/logging/log4j/core/appender/ log4j...
Date Mon, 21 Mar 2011 23:47:08 GMT
Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LineSeparatorPatternConverter.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/pattern/LineSeparatorPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LineSeparatorPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LineSeparatorPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.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/pattern/LiteralPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LiteralPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LogEventPatternConverter.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/pattern/LogEventPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LogEventPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LogEventPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LogEvent;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerPatternConverter.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/pattern/LoggerPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/LoggerPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -61,8 +61,6 @@ public final class LoggerPatternConverte
      * {@inheritDoc}
      */
     public void format(final LogEvent event, final StringBuilder toAppendTo) {
-        final int initialLength = toAppendTo.length();
-        toAppendTo.append(event.getLoggerName());
-        abbreviate(initialLength, toAppendTo);
+        toAppendTo.append(abbreviate(event.getLoggerName()));
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MDCPatternConverter.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/pattern/MDCPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MDCPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MDCPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,15 +15,13 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
 
 import java.util.Map;
 import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeMap;
 import java.util.TreeSet;
 
 /**

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.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/pattern/MessagePatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MessagePatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MethodLocationPatternConverter.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/pattern/MethodLocationPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MethodLocationPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/MethodLocationPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NDCPatternConverter.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/pattern/NDCPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NDCPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NDCPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.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/pattern/NameAbbreviator.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NameAbbreviator.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -124,12 +124,12 @@ public abstract class NameAbbreviator {
     }
 
     /**
-     * Abbreviates a name in a StringBuffer.
+     * Abbreviates a name in a String.
      *
-     * @param nameStart starting position of name in buf.
      * @param buf       buffer, may not be null.
+     * @return The abbreviated String.
      */
-    public abstract void abbreviate(final int nameStart, final StringBuilder buf);
+    public abstract String abbreviate(final String buf);
 
     /**
      * Abbreviator that simply appends full name to buffer.
@@ -144,7 +144,8 @@ public abstract class NameAbbreviator {
         /**
          * {@inheritDoc}
          */
-        public void abbreviate(final int nameStart, final StringBuilder buf) {
+        public String abbreviate(final String buf) {
+            return buf;
         }
     }
 
@@ -169,27 +170,24 @@ public abstract class NameAbbreviator {
         /**
          * Abbreviate name.
          *
-         * @param buf       buffer to append abbreviation.
-         * @param nameStart start of name to abbreviate.
+         * @param buf The String to abbreviate.
+         * @return the abbreviated String.
          */
-        public void abbreviate(final int nameStart, final StringBuilder buf) {
-            int len = buf.length() - nameStart;
+        public String abbreviate(final String buf) {
 
             // We substract 1 from 'len' when assigning to 'end' to avoid out of
             // bounds exception in return r.substring(end+1, len). This can happen if
             // precision is 1 and the category name ends with a dot.
             int end = buf.length() - 1;
 
-            String bufString = buf.toString();
             for (int i = count; i > 0; i--) {
-                end = bufString.lastIndexOf(".", end - 1);
-
-                if ((end == -1) || (end < nameStart)) {
-                    return;
+                end = buf.lastIndexOf(".", end - 1);
+                if (end == -1) {
+                    return buf;
                 }
             }
 
-            buf.delete(nameStart, end + 1);
+            return buf.substring(end + 1);
         }
     }
 
@@ -279,15 +277,16 @@ public abstract class NameAbbreviator {
          * @param buf       buffer that abbreviated name is appended.
          * @param nameStart start of name.
          */
-        public void abbreviate(final int nameStart, final StringBuilder buf) {
+        public String abbreviate(final String buf) {
             //
             //  all non-terminal patterns are executed once
             //
-            int pos = nameStart;
+            int pos = 0;
+            StringBuilder sb = new StringBuilder(buf);
 
             for (int i = 0; (i < (fragments.length - 1)) && (pos < buf.length());
                  i++) {
-                pos = fragments[i].abbreviate(buf, pos);
+                pos = fragments[i].abbreviate(sb, pos);
             }
 
             //
@@ -296,8 +295,9 @@ public abstract class NameAbbreviator {
             PatternAbbreviatorFragment terminalFragment = fragments[fragments.length - 1];
 
             while ((pos < buf.length()) && (pos >= 0)) {
-                pos = terminalFragment.abbreviate(buf, pos);
+                pos = terminalFragment.abbreviate(sb, pos);
             }
+            return sb.toString();
         }
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NamePatternConverter.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/pattern/NamePatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NamePatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/NamePatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 
 /**
@@ -47,10 +47,10 @@ public abstract class NamePatternConvert
     /**
      * Abbreviate name in string buffer.
      *
-     * @param nameStart starting position of name to abbreviate.
      * @param buf       string buffer containing name.
+     * @return The abbreviated name.
      */
-    protected final void abbreviate(final int nameStart, final StringBuilder buf) {
-        abbreviator.abbreviate(nameStart, buf);
+    protected final String abbreviate(final String buf) {
+        return abbreviator.abbreviate(buf);
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternConverter.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/pattern/PatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 
 /**

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.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/pattern/PatternParser.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/PatternParser.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.PluginManager;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RelativeTimePatternConverter.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/pattern/RelativeTimePatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RelativeTimePatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/RelativeTimePatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.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/pattern/SequenceNumberPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/SequenceNumberPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadPatternConverter.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/pattern/ThreadPatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadPatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadPatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.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/pattern/ThrowablePatternConverter.java?rev=1084027&r1=1074871&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/main/java/org/apache/logging/log4j/core/pattern/ThrowablePatternConverter.java Mon Mar 21 23:47:06 2011
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.plugins.Plugin;

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/PerformanceComparison.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/PerformanceComparison.java?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/PerformanceComparison.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/PerformanceComparison.java Mon Mar 21 23:47:06 2011
@@ -0,0 +1,192 @@
+/*
+ * 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.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.apache.logging.log4j.core.util.Profiler;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+import java.nio.charset.Charset;
+
+/**
+ *
+ */
+public class PerformanceComparison {
+
+    private Logger logger = LogManager.getLogger(PerformanceComparison.class.getName());
+    private org.slf4j.Logger logbacklogger = org.slf4j.LoggerFactory.getLogger(PerformanceComparison.class);
+    private org.apache.log4j.Logger log4jlogger = org.apache.log4j.Logger.getLogger(PerformanceComparison.class);
+
+
+    // How many times should we try to log:
+    private static final int COUNT = 1000000;
+    private static final int PROFILE_COUNT = 500000;
+    private static final int WARMUP = 1000;
+
+    private static final String CONFIG = "log4j2-perf.xml";
+    private static final String LOGBACK_CONFIG = "logback-perf.xml";
+    private static final String LOG4J_CONFIG = "log4j12-perf.xml";
+
+    private static final String LOGBACK_CONF = "logback.configurationFile";
+    private static final String LOG4J_CONF = "log4j.configuration";
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+        System.setProperty(LOGBACK_CONF, LOGBACK_CONFIG);
+        System.setProperty(LOG4J_CONF, LOG4J_CONFIG);
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+        System.clearProperty(LOGBACK_CONF);
+        System.clearProperty(LOG4J_CONF);
+    }
+
+    @Test
+    public void testPerformance() throws Exception {
+
+        log4j(WARMUP);
+        logback(WARMUP);
+        log4j2(WARMUP);
+
+        if (Profiler.isActive()) {
+            System.out.println("Profiling Log4j 2.0");
+            Profiler.start();
+            long result = log4j2(PROFILE_COUNT);
+            Profiler.stop();
+            System.out.println("###############################################");
+            System.out.println("Log4j 2.0: " + result);
+            System.out.println("###############################################");
+        } else {
+            System.out.println("Starting Log4j 2.0");
+            long result3 = log4j2(COUNT);
+            System.out.println("Starting Log4j");
+            long result1 = log4j(COUNT);
+            System.out.println("Starting Logback");
+            long result2 = logback(COUNT);
+
+            System.out.println("###############################################");
+            System.out.println("Log4j: " + result1);
+            System.out.println("Logback: " + result2);
+            System.out.println("Log4j 2.0: " + result3);
+            System.out.println("###############################################");
+        }
+    }
+
+    //@Test
+    public void testRawPerformance() throws Exception {
+        OutputStream os = new FileOutputStream("target/testos.log", true);
+        long result1 = writeToStream(COUNT, os);
+        os.close();
+        OutputStream bos = new BufferedOutputStream(new FileOutputStream("target/testbuffer.log", true));
+        long result2 = writeToStream(COUNT, bos);
+        bos.close();
+        Writer w = new FileWriter("target/testwriter.log", true);
+        long result3 = writeToWriter(COUNT, w);
+        w.close();
+        FileOutputStream cos = new FileOutputStream("target/testchannel.log", true);
+        FileChannel channel = cos.getChannel();
+        long result4 = writeToChannel(COUNT, channel);
+        cos.close();
+        System.out.println("###############################################");
+        System.out.println("FileOutputStream: " + result1);
+        System.out.println("BufferedOutputStream: " + result2);
+        System.out.println("FileWriter: " + result3);
+        System.out.println("FileChannel: " + result4);
+        System.out.println("###############################################");
+    }
+
+    private long log4j(int loop) {
+        Integer j = new Integer(2);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            log4jlogger.debug("SEE IF THIS IS LOGGED " + j + ".");
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+    private long logback(int loop) {
+        Integer j = new Integer(2);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            logbacklogger.debug("SEE IF THIS IS LOGGED " + j + ".");
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+
+    private long log4j2(int loop) {
+        Integer j = new Integer(2);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            logger.debug("SEE IF THIS IS LOGGED " + j + ".");
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+
+    private long writeToWriter(int loop, Writer w) throws Exception {
+        Integer j = new Integer(2);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            w.write("SEE IF THIS IS LOGGED " + j + ".");
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+    private long writeToStream(int loop, OutputStream os) throws Exception {
+        Integer j = new Integer(2);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            os.write(getBytes("SEE IF THIS IS LOGGED " + j + "."));
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+    private long writeToChannel(int loop, FileChannel channel) throws Exception {
+        Integer j = new Integer(2);
+        ByteBuffer buf = ByteBuffer.allocateDirect(8*1024);
+        long start = System.nanoTime();
+        for (int i = 0; i < loop; i++) {
+            channel.write(getByteBuffer(buf, "SEE IF THIS IS LOGGED " + j + "."));
+        }
+        return (System.nanoTime() - start) / loop;
+    }
+
+    private ByteBuffer getByteBuffer(ByteBuffer buf, String s) {
+        buf.clear();
+        buf.put(s.getBytes());
+        buf.flip();
+        return buf;
+    }
+
+    private byte[] getBytes(String s) {
+        return s.getBytes();
+    }
+
+}
\ No newline at end of file

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java?rev=1084027&r1=1084026&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/SimplePerfTest.java Mon Mar 21 23:47:06 2011
@@ -18,13 +18,13 @@ package org.apache.logging.log4j.core;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.DefaultConfiguration;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.Assert;
 
 import java.util.Random;
-import java.util.UUID;
-import java.util.logging.LogRecord;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
@@ -49,6 +49,12 @@ public class SimplePerfTest {
     @BeforeClass
     public static void setupClass() {
 
+        Configuration config = ((LoggerContext)LogManager.getContext()).getConfiguration();
+        if (!DefaultConfiguration.DEFAULT_NAME.equals(config.getName())) {
+            System.out.println("Configuration was " + config.getName());
+            ((LoggerContext)LogManager.getContext()).setConfiguration(new DefaultConfiguration());
+        }
+
         Random r = new Random(WARMUP);
 
         for (int i=0; i < RAND_SIZE; ++i) {
@@ -87,10 +93,12 @@ public class SimplePerfTest {
 
     @Test
     public void debugLogger() {
+        System.gc();
         Timer timer = new Timer("DebugLogger", LOOP_CNT);
+        String msg = "This is a test";
         timer.start();
         for (int i=0; i < LOOP_CNT; ++i) {
-            logger.debug("This is a test");
+            logger.debug(msg);
         }
         timer.stop();
         System.out.println(timer.toString());

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/FileAppenderTest.java Mon Mar 21 23:47:06 2011
@@ -0,0 +1,241 @@
+/*
+ * 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.Level;
+import org.apache.logging.log4j.ThreadContext;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.message.SimpleMessage;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class FileAppenderTest {
+
+    private static final String FILENAME = "target/fileAppenderTest.log";
+    private static final int THREADS = 2;
+
+    @BeforeClass
+    public static void setupClass() {
+        deleteFile();
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        deleteFile();
+        assertTrue("Manager for " + FILENAME + " not removed", !OutputStreamManager.hasManager(FILENAME));
+    }
+
+    @After
+    public void teardown() {
+        deleteFile();
+    }
+
+    @Test
+    public void testAppender() throws Exception {
+        writer(false, 1, "test");
+        verifyFile(1);
+    }
+
+    @Test
+    public void testLockingAppender() throws Exception {
+        writer(true, 1, "test");
+        verifyFile(1);
+    }
+
+    @Test
+    public void testMultipleAppenders() throws Exception {
+        ExecutorService pool = Executors.newFixedThreadPool(THREADS);
+        int count = 10;
+        Runnable runnable = new FileWriterRunnable(false, count);
+        for (int i=0; i < THREADS; ++i) {
+            pool.execute(runnable);
+        }
+        pool.shutdown();
+        pool.awaitTermination(10, TimeUnit.SECONDS);
+        verifyFile(THREADS * count);
+    }
+
+
+    @Test
+    public void testMultipleLockedAppenders() throws Exception {
+        ExecutorService pool = Executors.newFixedThreadPool(THREADS);
+        int count = 10;
+        Runnable runnable = new FileWriterRunnable(true, count);
+        for (int i=0; i < THREADS; ++i) {
+            pool.execute(runnable);
+        }
+        pool.shutdown();
+        pool.awaitTermination(10, TimeUnit.SECONDS);
+        verifyFile(THREADS * count);
+    }
+
+
+    //@Test
+    public void testMultipleVMs() throws Exception {
+
+        String classPath = System.getProperty("java.class.path");
+        Integer count = 10;
+        int processes = 3;
+        Process[] process = new Process[processes];
+        ProcessBuilder[] builders = new ProcessBuilder[processes];
+        for (int index=0; index < processes; ++index) {
+            builders[index] = new ProcessBuilder("java","-cp", classPath, ProcessTest.class.getName(),
+                "Process " + index, count.toString(), "true");
+        }
+        for (int index=0; index < processes; ++index) {
+            process[index] = builders[index].start();
+        }
+        for (int index=0; index < processes; ++index) {
+            Process p = process[index];
+            //System.out.println("Process " + index + " exited with " + p.waitFor());
+            InputStream is = p.getInputStream();
+            InputStreamReader isr = new InputStreamReader(is);
+            BufferedReader br = new BufferedReader(isr);
+            String line;
+            while ((line = br.readLine()) != null) {
+                System.out.println(line);
+            }
+
+            p.destroy();
+        }
+        verifyFile(count * processes);
+    }
+
+    private static void writer(boolean lock, int count, String name) throws Exception {
+        Layout layout = new PatternLayout(PatternLayout.SIMPLE_CONVERSION_PATTERN);
+        FileManager manager = FileManager.getFileManager(FILENAME, true, lock, false);
+        FileAppender app = new FileAppender("test", layout, null, manager, FILENAME, false, false);
+        Thread t = Thread.currentThread();
+        app.start();
+        assertTrue("Appender did not start", app.isStarted());
+        for (int i=0; i < count; ++i) {
+            LogEvent event = new Log4jLogEvent("TestLogger", null, FileAppenderTest.class.getName(), Level.INFO,
+                new SimpleMessage("Test"), null, null, null, name, null, System.currentTimeMillis());
+            try {
+                app.append(event);
+                t.sleep(25);  // Give up control long enough for another thread/process to occasionally do something.
+            } catch (Exception ex) {
+                throw ex;
+            }
+        }
+        app.stop();
+        assertFalse("Appender did not stop", app.isStarted());
+    }
+
+    private void verifyFile(int count) throws Exception {
+        //String expected = "[\\w]* \\[\\s*\\] INFO TestLogger - Test$";
+        String expected = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} \\[[^\\]]*\\] INFO TestLogger - Test";
+        Pattern pattern = Pattern.compile(expected);
+        DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(FILENAME)));
+        int counter = 0;
+        String str = "";
+        while (is.available() != 0) {
+            str = is.readLine();
+            //System.out.println(str);
+            ++counter;
+            Matcher matcher = pattern.matcher(str);
+            assertTrue("Bad data: " + str, matcher.matches());
+        }
+        assertTrue("Incorrect count: was " + counter + " should be " + counter, count == counter);
+
+    }
+
+
+    private static void deleteFile() {
+        File file = new File(FILENAME);
+        if (file.exists()) {
+            file.delete();
+        }
+    }
+
+    public class FileWriterRunnable implements Runnable {
+        private final boolean lock;
+        private final int count;
+
+        public FileWriterRunnable(boolean lock, int count)  {
+            this.lock = lock;
+            this.count = count;
+        }
+        public void run() {
+            Thread thread = Thread.currentThread();
+
+            try {
+                writer(lock, count, thread.getName());
+
+            } catch (Exception ex) {
+                throw new RuntimeException(ex);
+            }
+        }
+    }
+
+    public static class ProcessTest {
+
+        public static void main(String[] args) {
+
+            if (args.length != 3) {
+                System.out.println("Required arguments 'id', 'count' and 'lock' not provided");
+                System.exit(-1);
+            }
+            String id = args[0];
+
+            int count = Integer.parseInt(args[1]);
+
+            if (count <= 0) {
+                System.out.println("Invalid count value: " + args[1]);
+                System.exit(-1);
+            }
+            boolean lock = Boolean.parseBoolean(args[2]);
+
+            //System.out.println("Got arguments " + id + ", " + count + ", " + lock);
+
+            try {
+                writer(lock, count, id);
+                //thread.sleep(50);
+
+            } catch (Exception ex) {
+                throw new RuntimeException(ex);
+            }
+
+
+        }
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppender.java?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppender.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/InMemoryAppender.java Mon Mar 21 23:47:06 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.Layout;
+import org.apache.logging.log4j.core.filter.Filters;
+
+import java.io.ByteArrayOutputStream;
+
+/**
+ *
+ */
+public class InMemoryAppender extends OutputStreamAppender {
+
+    public InMemoryAppender(String name, Layout layout, Filters filters, boolean handleException) {
+        super(name, layout, filters, handleException, true, new InMemoryManager(name));
+    }
+
+    public String toString() {
+        return getManager().toString();
+    }
+
+    private static class InMemoryManager extends OutputStreamManager {
+
+        public InMemoryManager(String name) {
+            super(new ByteArrayOutputStream(), name);
+        }
+
+        public String toString() {
+            return getOutputStream().toString();
+        }
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/appender/OutputStreamAppenderTest.java Mon Mar 21 23:47:06 2011
@@ -0,0 +1,53 @@
+/*
+ * 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.Level;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.Log4jLogEvent;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.message.SimpleMessage;
+
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+/**
+ *
+ */
+public class OutputStreamAppenderTest {
+
+
+    @Test
+    public void testAppender() {
+        Layout layout = new PatternLayout();
+        InMemoryAppender app = new InMemoryAppender("test", layout, null, false);
+        LogEvent event = new Log4jLogEvent("TestLogger", null, OutputStreamAppenderTest.class.getName(), Level.INFO,
+            new SimpleMessage("Test"), null);
+        app.start();
+        assertTrue("Appender did not start", app.isStarted());
+        app.append(event);
+        String msg = app.toString();
+        assertNotNull("No message", msg);
+        assertTrue("Incorrect message: " + msg , msg.endsWith("Test\n"));
+        app.stop();
+        assertFalse("Appender did not stop", app.isStarted());
+    }
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java?rev=1084027&r1=1084026&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/config/XMLConfigurationTest.java Mon Mar 21 23:47:06 2011
@@ -28,6 +28,10 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -41,6 +45,7 @@ import static org.junit.Assert.assertEqu
 public class XMLConfigurationTest {
 
     private static final String CONFIG = "log4j-test1.xml";
+    private static final String LOGFILE = "target/test.log";
 
     @BeforeClass
     public static void setupClass() {
@@ -93,9 +98,21 @@ public class XMLConfigurationTest {
     }
 
     @Test
-    public void logToFile() {
+    public void logToFile() throws Exception {
+        FileOutputStream fos = new FileOutputStream(LOGFILE, false);
+        fos.flush();
+        fos.close();
         Logger logger = LogManager.getLogger("org.apache.logging.log4j.test2.Test");
         logger.debug("This is a test");
+        DataInputStream is = new DataInputStream(new BufferedInputStream(new FileInputStream(LOGFILE)));
+        int count = 0;
+        String str = "";
+        while (is.available() != 0) {
+            str = is.readLine();
+            ++count;
+        }
+        assertTrue("Incorrect count " + count, count == 1);
+        assertTrue("Bad data", str.endsWith("This is a test"));
     }
 
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java?rev=1084027&r1=1084026&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/layout/PatternLayoutTest.java Mon Mar 21 23:47:06 2011
@@ -25,6 +25,7 @@ import org.apache.logging.log4j.core.Log
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.BasicConfigurationFactory;
 import org.apache.logging.log4j.core.appender.FileAppender;
+import org.apache.logging.log4j.core.appender.FileManager;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.util.Compare;
 import org.junit.AfterClass;
@@ -39,7 +40,7 @@ import static org.junit.Assert.assertTru
  *
  */
 public class PatternLayoutTest {
-    static String OUTPUT_FILE   = "output/PatternParser";
+    static String OUTPUT_FILE   = "target/output/PatternParser";
     static String WITNESS_FILE  = "witness/PatternParser";
     LoggerContext ctx = (LoggerContext) LogManager.getContext();
     Logger root = ctx.getLogger("");
@@ -74,8 +75,9 @@ public class PatternLayoutTest {
 
         // set up appender
         PatternLayout layout = new PatternLayout(msgPattern);
-        FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
-        FileAppender appender = new FileAppender("File", layout, null, fos, OUTPUT_FILE + "_mdc");
+        //FileOutputStream fos = new FileOutputStream(OUTPUT_FILE + "_mdc");
+        FileManager manager = FileManager.getFileManager(OUTPUT_FILE + "_mdc", false, false, false);
+        FileAppender appender = new FileAppender("File", layout, null, manager, OUTPUT_FILE + "_mdc", true, false);
         appender.start();
 
         // set appender on root and set level to debug
@@ -125,5 +127,7 @@ public class PatternLayoutTest {
         root.debug("finished mdc pattern test");
 
         assertTrue(Compare.compare(this.getClass(), OUTPUT_FILE + "_mdc", WITNESS_FILE + "_mdc"));
+
+        appender.stop();
     }
 }

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java?rev=1084027&r1=1025816&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/pattern/PatternParserTest.java Mon Mar 21 23:47:06 2011
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-package org.apache.logging.log4j.core.layout.pattern;
+package org.apache.logging.log4j.core.pattern;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -22,14 +22,12 @@ import org.apache.logging.log4j.core.Log
 
 import org.junit.Before;
 import org.junit.Test;
-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 java.io.FileOutputStream;
 import java.util.List;
 
 /**

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Profiler.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Profiler.java?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Profiler.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/java/org/apache/logging/log4j/core/util/Profiler.java Mon Mar 21 23:47:06 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Field;
+
+/**
+ *
+ */
+public class Profiler {
+    private static Object profiler;
+    private static Class profilingModes;
+    private static Class controllerClazz;
+
+    static {
+        try {
+            controllerClazz = Class.forName("com.yourkit.api.Controller");
+            profilingModes = Class.forName("com.yourkit.api.ProfilingModes");
+            try {
+                profiler = controllerClazz.newInstance();
+            } catch (Exception e) {
+                e.printStackTrace();
+                System.out.println("Profiler was active, but failed due: " + e.getMessage());
+            }
+        }
+        catch (Exception e) {
+            // Ignore
+        }
+
+    }
+
+    public static boolean isActive() {
+        return profiler != null;
+    }
+
+    public static void start() {
+
+        if (profiler != null) {
+            try {
+                Field f = profilingModes.getDeclaredField("CPU_SAMPLING");
+                Object[] args = new Object[2];
+                args[0] = f.getLong(profilingModes);
+                args[1] = "";
+                Class[] parms = new Class[] {long.class, String.class};
+                controllerClazz.getMethod("startCPUProfiling", parms).invoke(profiler, args);
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                System.out.println("Profiler was active, but failed due: " + e.getMessage());
+            }
+        }
+    }
+
+    public static void stop() {
+        if (profiler != null) {
+            try {
+                Field f = profilingModes.getDeclaredField("SNAPSHOT_WITHOUT_HEAP");
+                Object[] args = new Object[1];
+                args[0] = f.getLong(profilingModes);
+                Class[] parms = new Class[] {long.class};
+                profiler.getClass().getMethod("captureSnapshot", parms).invoke(profiler, args);
+                profiler.getClass().getMethod("stopCPUProfiling").invoke(profiler);
+            }
+            catch (Exception e) {
+                e.printStackTrace();
+                System.out.println("Profiler was active, but failed due: " + e.getMessage());
+            }
+        }
+    }
+}

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml?rev=1084027&r1=1084026&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j-test1.xml Mon Mar 21 23:47:06 2011
@@ -11,7 +11,7 @@
     <Console name="STDOUT">
       <PatternLayout pattern="%m%n"/>
     </Console>
-    <File name="File" fileName="${filename}">
+    <File name="File" fileName="${filename}" bufferedIO="false">
       <PatternLayout>
         <pattern>%d %p %C{1.} [%t] %m%n</pattern>
       </PatternLayout>

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j12-perf.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j12-perf.xml?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j12-perf.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j12-perf.xml Mon Mar 21 23:47:06 2011
@@ -0,0 +1,14 @@
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+ <appender name="TestLogfile" class="org.apache.log4j.FileAppender">
+   <param name="File" value="target/testlog4j.log"/>
+   <param name="immediateFlush" value="false"/>
+   <layout class="org.apache.log4j.PatternLayout">
+     <param name="ConversionPattern" value="%d{ISO8601} %5p [%t] %c{1} %X{transactionId} - %m%n"/>
+   </layout>
+ </appender>
+ <root>
+   <level value="debug"/>
+   <appender-ref ref="TestLogfile"/>
+ </root>
+</log4j:configuration>
\ No newline at end of file

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j2-perf.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j2-perf.xml?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j2-perf.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/log4j2-perf.xml Mon Mar 21 23:47:06 2011
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration packages="" name="XMLPerfTest" status="error">
+  <appenders>
+    <File name="TestLogfile" fileName="target/testlog4j2.log" immediateFlush="false">
+      <PatternLayout>
+        <pattern>%d{ISO8601} %5p [%t] %c{1} %X{transactionId} - %m%n</pattern>
+      </PatternLayout>
+    </File>
+  </appenders>
+  <loggers>
+    <root level="debug">
+      <appender-ref ref="TestLogfile"/>
+    </root>
+  </loggers>
+</configuration>
\ No newline at end of file

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-perf.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-perf.xml?rev=1084027&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-perf.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/log4j2-core/src/test/resources/logback-perf.xml Mon Mar 21 23:47:06 2011
@@ -0,0 +1,12 @@
+<configuration>
+ <appender name="TestLogfile" class="ch.qos.logback.core.FileAppender">
+   <file>target/testlogback.log</file>
+   <encoder>
+     <Pattern>%d{ISO8601} %5p [%t] %c{0} %X{transactionId} - %m%n</Pattern>
+   </encoder>
+ </appender>
+
+ <root level="debug">
+   <appender-ref ref="TestLogfile" />
+ </root>
+</configuration>
\ No newline at end of file

Modified: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/pom.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/pom.xml?rev=1084027&r1=1084026&r2=1084027&view=diff
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/pom.xml (original)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/pom.xml Mon Mar 21 23:47:06 2011
@@ -23,6 +23,11 @@
   <packaging>pom</packaging>
   <name>Apache Log4j 2</name>
   <version>1.99.0-SNAPSHOT</version>
+  <parent>
+    <groupId>org.apache</groupId>
+    <artifactId>apache</artifactId>
+    <version>9</version>
+  </parent>
   <description>Apache Log4j 2</description>
   <url>http://logging.apache.org/log4j/2.0/</url>
   <issueManagement>
@@ -77,6 +82,7 @@
   </organization>
   <properties>
     <slf4j.version>1.6.1</slf4j.version>
+    <logback.version>0.9.28</logback.version>
   </properties>
   <dependencyManagement>
     <dependencies>
@@ -91,6 +97,16 @@
         <version>${slf4j.version}</version>
       </dependency>
       <dependency>
+        <groupId>ch.qos.logback</groupId>
+        <artifactId>logback-core</artifactId>
+        <version>${logback.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>ch.qos.logback</groupId>
+        <artifactId>logback-classic</artifactId>
+        <version>${logback.version}</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.logging</groupId>
         <artifactId>log4j2-api</artifactId>
         <version>${project.version}</version>



---------------------------------------------------------------------
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