You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/24 17:16:28 UTC

[01/11] logging-log4j2 git commit: FIX NPE in RingBufferLogEventTest

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1278-gc-free-logger d3e3947e9 -> 5a873ddf0


FIX NPE in RingBufferLogEventTest


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/20be2b03
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/20be2b03
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/20be2b03

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 20be2b03dd82875a225f1ecb607edf3ed1896587
Parents: a0a4e43
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 23 08:37:27 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 23 08:37:27 2016 +0900

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/async/RingBufferLogEvent.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/20be2b03/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 10347a3..a241f0a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -163,7 +163,7 @@ public class RingBufferLogEvent implements LogEvent {
             ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
         } else {
             // if the Message instance is reused, there is no point in freezing its message here
-            if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND) { // LOG4J2-898: user may choose
+            if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose
                 msg.getFormattedMessage(); // LOG4J2-763: ask message to freeze parameters
             }
             this.message = msg;


[10/11] logging-log4j2 git commit: LOG4J2-1296 simplify RingBufferLogEvent: remove inner class StringBuilderWrapperMessage and implement the Message interface directly

Posted by rp...@apache.org.
LOG4J2-1296 simplify RingBufferLogEvent: remove inner class StringBuilderWrapperMessage and implement the Message interface directly


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/29a4e87d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/29a4e87d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/29a4e87d

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 29a4e87d1636e1f3473a850f68e005b4dbe44695
Parents: f41322b
Author: rpopma <rp...@apache.org>
Authored: Fri Mar 25 01:15:17 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Mar 25 01:15:17 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/async/RingBufferLogEvent.java    | 97 +++++++++-----------
 1 file changed, 44 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/29a4e87d/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index a241f0a..399c7a5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -41,7 +41,7 @@ import com.lmax.disruptor.EventFactory;
  * When the Disruptor is started, the RingBuffer is populated with event objects. These objects are then re-used during
  * the life of the RingBuffer.
  */
-public class RingBufferLogEvent implements LogEvent {
+public class RingBufferLogEvent implements LogEvent, ReusableMessage {
 
     /** The {@code EventFactory} for {@code RingBufferLogEvent}s. */
     public static final Factory FACTORY = new Factory();
@@ -49,6 +49,8 @@ public class RingBufferLogEvent implements LogEvent {
     private static final long serialVersionUID = 8462119088943934758L;
     private static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
     private static final int MAX_REUSABLE_MESSAGE_SIZE = size("log4j.maxReusableMsgSize", (128 * 2 + 2) * 2 + 2);
+    private static final Object[] PARAMS = new Object[0];
+    private static final Message EMPTY = new SimpleMessage(Strings.EMPTY);
 
     private static int size(final String property, final int defaultValue) {
         return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
@@ -69,53 +71,6 @@ public class RingBufferLogEvent implements LogEvent {
         }
     }
 
-    private static class StringBuilderWrapperMessage implements ReusableMessage {
-        static final StringBuilderWrapperMessage INSTANCE = new StringBuilderWrapperMessage();
-        private static final Object[] PARAMS = new Object[0];
-        private StringBuilder stringBuilder;
-
-        @Override
-        public String getFormattedMessage() {
-            final String result = stringBuilder.toString();
-            trim(stringBuilder, MAX_REUSABLE_MESSAGE_SIZE);
-            return result;
-        }
-
-        @Override
-        public String getFormat() {
-            return null;
-        }
-
-        @Override
-        public Object[] getParameters() {
-            return PARAMS;
-        }
-
-        @Override
-        public Throwable getThrowable() {
-            return null;
-        }
-
-        @Override
-        public void formatTo(final StringBuilder buffer) {
-            buffer.append(stringBuilder);
-            trim(stringBuilder, MAX_REUSABLE_MESSAGE_SIZE);
-        }
-
-        // ensure that excessively long char[] arrays are not kept in memory forever
-        private static void trim(final StringBuilder sb, final int maxReusableMessageSize) {
-            if (sb.length() > maxReusableMessageSize) {
-                sb.setLength(maxReusableMessageSize);
-                sb.trimToSize();
-            }
-        }
-
-        public Message setFormattedMessage(final StringBuilder messageText) {
-            this.stringBuilder = messageText;
-            return this;
-        }
-    }
-
     private transient AsyncLogger asyncLogger;
     private String loggerName;
     private Marker marker;
@@ -241,15 +196,51 @@ public class RingBufferLogEvent implements LogEvent {
     @Override
     public Message getMessage() {
         if (message == null) {
-            if (messageText == null) {
-                message = new SimpleMessage(Strings.EMPTY);
-            } else {
-                message = StringBuilderWrapperMessage.INSTANCE.setFormattedMessage(messageText);
-            }
+            return (messageText == null) ? EMPTY : this;
         }
         return message;
     }
 
+    /**
+     * @see ReusableMessage#getFormattedMessage()
+     */
+    @Override
+    public String getFormattedMessage() {
+        return messageText.toString();
+    }
+
+    /**
+     * @see ReusableMessage#getFormat()
+     */
+    @Override
+    public String getFormat() {
+        return null;
+    }
+
+    /**
+     * @see ReusableMessage#getParameters()
+     */
+    @Override
+    public Object[] getParameters() {
+        return PARAMS;
+    }
+
+    /**
+     * @see ReusableMessage#getThrowable()
+     */
+    @Override
+    public Throwable getThrowable() {
+        return getThrown();
+    }
+
+    /**
+     * @see ReusableMessage#formatTo(StringBuilder)
+     */
+    @Override
+    public void formatTo(final StringBuilder buffer) {
+        buffer.append(messageText);
+    }
+
     private Message getNonNullImmutableMessage() {
         return message != null ? message : new SimpleMessage(String.valueOf(messageText));
     }


[05/11] logging-log4j2 git commit: Fix GcFreeLoggingTest

Posted by rp...@apache.org.
Fix GcFreeLoggingTest


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/13859245
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/13859245
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/13859245

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 138592456d36ebc9ef1cc24e0a842d35fe729801
Parents: 80cc833
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed Mar 23 14:45:56 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed Mar 23 14:45:56 2016 +0100

----------------------------------------------------------------------
 .../logging/log4j/core/GcFreeLoggingTest.java    |  6 +++---
 log4j-core/src/test/resources/gcFreeLogging.xml  | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/13859245/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
index 4a52ff6..00fa319 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
@@ -68,7 +68,7 @@ public class GcFreeLoggingTest {
     public static void main(String[] args) throws Exception {
         System.setProperty("log4j2.enable.threadlocals", "true");
         System.setProperty("log4j2.is.webapp", "false");
-        System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml");
+        System.setProperty("log4j.configurationFile", "gcFreeLogging.xml");
         System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName());
 
         assertTrue("Constants.ENABLE_THREADLOCALS", Constants.ENABLE_THREADLOCALS);
@@ -114,8 +114,8 @@ public class GcFreeLoggingTest {
             logger.error("Test parameterized message {}{}", "param", "param2");
             logger.error("Test parameterized message {}{}{}", "param", "param2", "abc");
         }
-        AllocationRecorder.removeSampler(sampler);
         Thread.sleep(50);
+        AllocationRecorder.removeSampler(sampler);
     }
 
     private static File agentJar() {
@@ -125,7 +125,7 @@ public class GcFreeLoggingTest {
             throw new IllegalStateException("Could not find url for " + name);
         }
         final String temp = url.toString();
-        final String path = temp.substring("jar:file:/".length(), temp.indexOf('!'));
+        final String path = temp.substring("jar:file:".length(), temp.indexOf('!'));
         return new File(path);
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/13859245/log4j-core/src/test/resources/gcFreeLogging.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/gcFreeLogging.xml b/log4j-core/src/test/resources/gcFreeLogging.xml
new file mode 100644
index 0000000..6cf9066
--- /dev/null
+++ b/log4j-core/src/test/resources/gcFreeLogging.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration status="OFF">
+  <Appenders>
+    <RandomAccessFile name="RandomAccessFilePattern" fileName="gcfree.log" immediateFlush="false" append="false">
+      <PatternLayout>
+        <Pattern>%d %p %c{1.} [%t] %X{aKey} %m %ex%n</Pattern>
+      </PatternLayout>
+    </RandomAccessFile>
+    <RandomAccessFile name="RandomAccessFileGelf" fileName="gcfree.json" immediateFlush="false" append="false">
+      <GelfLayout compressionType="OFF"/>
+    </RandomAccessFile>
+  </Appenders>
+  <Loggers>
+    <Root level="info" includeLocation="false">
+      <appender-ref ref="RandomAccessFilePattern"/>
+      <appender-ref ref="RandomAccessFileGelf"/>
+    </Root>
+  </Loggers>
+</Configuration>


[03/11] logging-log4j2 git commit: https://issues.apache.org/jira/browse/LOG4J2-1323 - Make life a little easier for advanced users.

Posted by rp...@apache.org.
https://issues.apache.org/jira/browse/LOG4J2-1323 - Make life a little
easier for advanced users.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/250f7200
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/250f7200
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/250f7200

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 250f720070e7c99508c125e41dbe9fea032f7bd3
Parents: 216d52e
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 22 18:15:28 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 22 18:15:28 2016 -0700

----------------------------------------------------------------------
 .../core/appender/rolling/PatternProcessor.java | 581 ++++++++++---------
 1 file changed, 300 insertions(+), 281 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/250f7200/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
index af5bcdb..e441c69 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/PatternProcessor.java
@@ -1,281 +1,300 @@
-/*
- * 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.rolling;
-
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.LogEvent;
-import org.apache.logging.log4j.core.impl.Log4jLogEvent;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
-import org.apache.logging.log4j.core.pattern.ArrayPatternConverter;
-import org.apache.logging.log4j.core.pattern.DatePatternConverter;
-import org.apache.logging.log4j.core.pattern.FormattingInfo;
-import org.apache.logging.log4j.core.pattern.PatternConverter;
-import org.apache.logging.log4j.core.pattern.PatternParser;
-import org.apache.logging.log4j.status.StatusLogger;
-
-/**
- * Parses the rollover pattern.
- */
-public class PatternProcessor {
-
-    protected static final Logger LOGGER = StatusLogger.getLogger();
-    private static final String KEY = "FileConverter";
-
-    private static final char YEAR_CHAR = 'y';
-    private static final char MONTH_CHAR = 'M';
-    private static final char[] WEEK_CHARS = {'w', 'W'};
-    private static final char[] DAY_CHARS = {'D', 'd', 'F', 'E'};
-    private static final char[] HOUR_CHARS = {'H', 'K', 'h', 'k'};
-    private static final char MINUTE_CHAR = 'm';
-    private static final char SECOND_CHAR = 's';
-    private static final char MILLIS_CHAR = 'S';
-
-    private final ArrayPatternConverter[] patternConverters;
-    private final FormattingInfo[] patternFields;
-
-    private long prevFileTime = 0;
-    private long nextFileTime = 0;
-
-    private RolloverFrequency frequency = null;
-
-    /**
-     * Constructor.
-     * @param pattern The file pattern.
-     */
-    public PatternProcessor(final String pattern) {
-        final PatternParser parser = createPatternParser();
-        final List<PatternConverter> converters = new ArrayList<>();
-        final List<FormattingInfo> fields = new ArrayList<>();
-        parser.parse(pattern, converters, fields, false, false);
-        final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
-        patternFields = fields.toArray(infoArray);
-        final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];
-        patternConverters = converters.toArray(converterArray);
-
-        for (final ArrayPatternConverter converter : patternConverters) {
-            if (converter instanceof DatePatternConverter) {
-                final DatePatternConverter dateConverter = (DatePatternConverter) converter;
-                frequency = calculateFrequency(dateConverter.getPattern());
-            }
-        }
-    }
-
-    /**
-     * Returns the next potential rollover time.
-     * @param currentMillis The current time.
-     * @param increment The increment to the next time.
-     * @param modulus If true the time will be rounded to occur on a boundary aligned with the increment.
-     * @return the next potential rollover time and the timestamp for the target file.
-     */
-    public long getNextTime(final long currentMillis, final int increment, final boolean modulus) {
-        //
-        // https://issues.apache.org/jira/browse/LOG4J2-1232
-        // Call setMinimalDaysInFirstWeek(7);
-        //
-        prevFileTime = nextFileTime;
-        long nextTime;
-
-        if (frequency == null) {
-            throw new IllegalStateException("Pattern does not contain a date");
-        }
-        final Calendar currentCal = Calendar.getInstance();
-        currentCal.setTimeInMillis(currentMillis);
-        final Calendar cal = Calendar.getInstance();
-        currentCal.setMinimalDaysInFirstWeek(7);
-        cal.setMinimalDaysInFirstWeek(7);
-        cal.set(currentCal.get(Calendar.YEAR), 0, 1, 0, 0, 0);
-        cal.set(Calendar.MILLISECOND, 0);
-        if (frequency == RolloverFrequency.ANNUALLY) {
-            increment(cal, Calendar.YEAR, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.YEAR, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.MONTH, currentCal.get(Calendar.MONTH));
-        if (frequency == RolloverFrequency.MONTHLY) {
-            increment(cal, Calendar.MONTH, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.MONTH, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        if (frequency == RolloverFrequency.WEEKLY) {
-            cal.set(Calendar.WEEK_OF_YEAR, currentCal.get(Calendar.WEEK_OF_YEAR));
-            increment(cal, Calendar.WEEK_OF_YEAR, increment, modulus);
-            cal.set(Calendar.DAY_OF_WEEK, currentCal.getFirstDayOfWeek());
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.WEEK_OF_YEAR, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.DAY_OF_YEAR, currentCal.get(Calendar.DAY_OF_YEAR));
-        if (frequency == RolloverFrequency.DAILY) {
-            increment(cal, Calendar.DAY_OF_YEAR, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.DAY_OF_YEAR, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.HOUR_OF_DAY, currentCal.get(Calendar.HOUR_OF_DAY));
-        if (frequency == RolloverFrequency.HOURLY) {
-            increment(cal, Calendar.HOUR_OF_DAY, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.HOUR_OF_DAY, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.MINUTE, currentCal.get(Calendar.MINUTE));
-        if (frequency == RolloverFrequency.EVERY_MINUTE) {
-            increment(cal, Calendar.MINUTE, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.MINUTE, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.SECOND, currentCal.get(Calendar.SECOND));
-        if (frequency == RolloverFrequency.EVERY_SECOND) {
-            increment(cal, Calendar.SECOND, increment, modulus);
-            nextTime = cal.getTimeInMillis();
-            cal.add(Calendar.SECOND, -1);
-            nextFileTime = cal.getTimeInMillis();
-            return debugGetNextTime(nextTime);
-        }
-        cal.set(Calendar.MILLISECOND, currentCal.get(Calendar.MILLISECOND));
-        increment(cal, Calendar.MILLISECOND, increment, modulus);
-        nextTime = cal.getTimeInMillis();
-        cal.add(Calendar.MILLISECOND, -1);
-        nextFileTime = cal.getTimeInMillis();
-        return debugGetNextTime(nextTime);
-    }
-
-    public void updateTime() {
-        prevFileTime = nextFileTime;
-    }
-
-    private long debugGetNextTime(final long nextTime) {
-        if (LOGGER.isTraceEnabled()) {
-            LOGGER.trace("PatternProcessor.getNextTime returning {}, nextFileTime={}, prevFileTime={}, current={}, freq={}", //
-                    format(nextTime), format(nextFileTime), format(prevFileTime), format(System.currentTimeMillis()), frequency);
-        }
-        return nextTime;
-    }
-
-    private String format(final long time) {
-        return new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss.SSS").format(new Date(time));
-    }
-
-    private void increment(final Calendar cal, final int type, final int increment, final boolean modulate) {
-        final int interval =  modulate ? increment - (cal.get(type) % increment) : increment;
-        cal.add(type, interval);
-    }
-
-    /**
-     * Format file name.
-     * @param buf string buffer to which formatted file name is appended, may not be null.
-     * @param obj object to be evaluated in formatting, may not be null.
-     */
-    public final void formatFileName(final StringBuilder buf, final Object obj) {
-        final long time = prevFileTime == 0 ? System.currentTimeMillis() : prevFileTime;
-        formatFileName(buf, new Date(time), obj);
-    }
-
-    /**
-     * Formats file name.
-     * @param subst The StrSubstitutor.
-     * @param buf string buffer to which formatted file name is appended, may not be null.
-     * @param obj object to be evaluated in formatting, may not be null.
-     */
-    public final void formatFileName(final StrSubstitutor subst, final StringBuilder buf, final Object obj) {
-        // LOG4J2-628: we deliberately use System time, not the log4j.Clock time
-        // for creating the file name of rolled-over files. 
-        final long time = prevFileTime == 0 ? System.currentTimeMillis() : prevFileTime;
-        formatFileName(buf, new Date(time), obj);
-        final LogEvent event = new Log4jLogEvent.Builder().setTimeMillis(time).build();
-        final String fileName = subst.replace(event, buf);
-        buf.setLength(0);
-        buf.append(fileName);
-    }
-
-    /**
-     * Formats file name.
-     * @param buf string buffer to which formatted file name is appended, may not be null.
-     * @param objects objects to be evaluated in formatting, may not be null.
-     */
-    protected final void formatFileName(final StringBuilder buf, final Object... objects) {
-        for (int i = 0; i < patternConverters.length; i++) {
-            final int fieldStart = buf.length();
-            patternConverters[i].format(buf, objects);
-
-            if (patternFields[i] != null) {
-                patternFields[i].format(fieldStart, buf);
-            }
-        }
-    }
-
-    private RolloverFrequency calculateFrequency(final String pattern) {
-        if (patternContains(pattern, MILLIS_CHAR)) {
-            return RolloverFrequency.EVERY_MILLISECOND;
-        }
-        if (patternContains(pattern, SECOND_CHAR)) {
-            return RolloverFrequency.EVERY_SECOND;
-        }
-        if (patternContains(pattern, MINUTE_CHAR)) {
-            return RolloverFrequency.EVERY_MINUTE;
-        }
-        if (patternContains(pattern, HOUR_CHARS)) {
-            return RolloverFrequency.HOURLY;
-        }
-        if (patternContains(pattern, DAY_CHARS)) {
-            return RolloverFrequency.DAILY;
-        }
-        if (patternContains(pattern, WEEK_CHARS)) {
-            return RolloverFrequency.WEEKLY;
-        }
-        if (patternContains(pattern, MONTH_CHAR)) {
-            return RolloverFrequency.MONTHLY;
-        }
-        if (patternContains(pattern, YEAR_CHAR)) {
-            return RolloverFrequency.ANNUALLY;
-        }
-        return null;
-    }
-
-    private PatternParser createPatternParser() {
-
-        return new PatternParser(null, KEY, null);
-    }
-
-    private boolean patternContains(final String pattern, final char... chars) {
-        for (final char character : chars) {
-            if (patternContains(pattern, character)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private boolean patternContains(final String pattern, final char character) {
-        return pattern.indexOf(character) >= 0;
-    }
-}
+/*
+ * 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.rolling;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.lookup.StrSubstitutor;
+import org.apache.logging.log4j.core.pattern.ArrayPatternConverter;
+import org.apache.logging.log4j.core.pattern.DatePatternConverter;
+import org.apache.logging.log4j.core.pattern.FormattingInfo;
+import org.apache.logging.log4j.core.pattern.PatternConverter;
+import org.apache.logging.log4j.core.pattern.PatternParser;
+import org.apache.logging.log4j.status.StatusLogger;
+
+/**
+ * Parses the rollover pattern.
+ */
+public class PatternProcessor {
+
+    protected static final Logger LOGGER = StatusLogger.getLogger();
+    private static final String KEY = "FileConverter";
+
+    private static final char YEAR_CHAR = 'y';
+    private static final char MONTH_CHAR = 'M';
+    private static final char[] WEEK_CHARS = {'w', 'W'};
+    private static final char[] DAY_CHARS = {'D', 'd', 'F', 'E'};
+    private static final char[] HOUR_CHARS = {'H', 'K', 'h', 'k'};
+    private static final char MINUTE_CHAR = 'm';
+    private static final char SECOND_CHAR = 's';
+    private static final char MILLIS_CHAR = 'S';
+
+    private final ArrayPatternConverter[] patternConverters;
+    private final FormattingInfo[] patternFields;
+
+    private long prevFileTime = 0;
+    private long nextFileTime = 0;
+
+    private RolloverFrequency frequency = null;
+    
+    private final String pattern;
+
+    public String getPattern() {
+        return pattern;
+    }
+
+    public String toString() {
+        return pattern;
+    }
+
+    /**
+     * Constructor.
+     * @param pattern The file pattern.
+     */
+    public PatternProcessor(final String pattern) {
+        this.pattern = pattern;
+        final PatternParser parser = createPatternParser();
+        final List<PatternConverter> converters = new ArrayList<>();
+        final List<FormattingInfo> fields = new ArrayList<>();
+        parser.parse(pattern, converters, fields, false, false);
+        final FormattingInfo[] infoArray = new FormattingInfo[fields.size()];
+        patternFields = fields.toArray(infoArray);
+        final ArrayPatternConverter[] converterArray = new ArrayPatternConverter[converters.size()];
+        patternConverters = converters.toArray(converterArray);
+
+        for (final ArrayPatternConverter converter : patternConverters) {
+            if (converter instanceof DatePatternConverter) {
+                final DatePatternConverter dateConverter = (DatePatternConverter) converter;
+                frequency = calculateFrequency(dateConverter.getPattern());
+            }
+        }
+    }
+
+    /**
+     * Returns the next potential rollover time.
+     * @param currentMillis The current time.
+     * @param increment The increment to the next time.
+     * @param modulus If true the time will be rounded to occur on a boundary aligned with the increment.
+     * @return the next potential rollover time and the timestamp for the target file.
+     */
+    public long getNextTime(final long currentMillis, final int increment, final boolean modulus) {
+        //
+        // https://issues.apache.org/jira/browse/LOG4J2-1232
+        // Call setMinimalDaysInFirstWeek(7);
+        //
+        prevFileTime = nextFileTime;
+        long nextTime;
+
+        if (frequency == null) {
+            throw new IllegalStateException("Pattern does not contain a date");
+        }
+        final Calendar currentCal = Calendar.getInstance();
+        currentCal.setTimeInMillis(currentMillis);
+        final Calendar cal = Calendar.getInstance();
+        currentCal.setMinimalDaysInFirstWeek(7);
+        cal.setMinimalDaysInFirstWeek(7);
+        cal.set(currentCal.get(Calendar.YEAR), 0, 1, 0, 0, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        if (frequency == RolloverFrequency.ANNUALLY) {
+            increment(cal, Calendar.YEAR, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.YEAR, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.MONTH, currentCal.get(Calendar.MONTH));
+        if (frequency == RolloverFrequency.MONTHLY) {
+            increment(cal, Calendar.MONTH, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.MONTH, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        if (frequency == RolloverFrequency.WEEKLY) {
+            cal.set(Calendar.WEEK_OF_YEAR, currentCal.get(Calendar.WEEK_OF_YEAR));
+            increment(cal, Calendar.WEEK_OF_YEAR, increment, modulus);
+            cal.set(Calendar.DAY_OF_WEEK, currentCal.getFirstDayOfWeek());
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.WEEK_OF_YEAR, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.DAY_OF_YEAR, currentCal.get(Calendar.DAY_OF_YEAR));
+        if (frequency == RolloverFrequency.DAILY) {
+            increment(cal, Calendar.DAY_OF_YEAR, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.DAY_OF_YEAR, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.HOUR_OF_DAY, currentCal.get(Calendar.HOUR_OF_DAY));
+        if (frequency == RolloverFrequency.HOURLY) {
+            increment(cal, Calendar.HOUR_OF_DAY, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.HOUR_OF_DAY, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.MINUTE, currentCal.get(Calendar.MINUTE));
+        if (frequency == RolloverFrequency.EVERY_MINUTE) {
+            increment(cal, Calendar.MINUTE, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.MINUTE, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.SECOND, currentCal.get(Calendar.SECOND));
+        if (frequency == RolloverFrequency.EVERY_SECOND) {
+            increment(cal, Calendar.SECOND, increment, modulus);
+            nextTime = cal.getTimeInMillis();
+            cal.add(Calendar.SECOND, -1);
+            nextFileTime = cal.getTimeInMillis();
+            return debugGetNextTime(nextTime);
+        }
+        cal.set(Calendar.MILLISECOND, currentCal.get(Calendar.MILLISECOND));
+        increment(cal, Calendar.MILLISECOND, increment, modulus);
+        nextTime = cal.getTimeInMillis();
+        cal.add(Calendar.MILLISECOND, -1);
+        nextFileTime = cal.getTimeInMillis();
+        return debugGetNextTime(nextTime);
+    }
+
+    public void updateTime() {
+        prevFileTime = nextFileTime;
+    }
+
+    private long debugGetNextTime(final long nextTime) {
+        if (LOGGER.isTraceEnabled()) {
+            LOGGER.trace("PatternProcessor.getNextTime returning {}, nextFileTime={}, prevFileTime={}, current={}, freq={}", //
+                    format(nextTime), format(nextFileTime), format(prevFileTime), format(System.currentTimeMillis()), frequency);
+        }
+        return nextTime;
+    }
+
+    private String format(final long time) {
+        return new SimpleDateFormat("yyyy/MM/dd-HH:mm:ss.SSS").format(new Date(time));
+    }
+
+    private void increment(final Calendar cal, final int type, final int increment, final boolean modulate) {
+        final int interval =  modulate ? increment - (cal.get(type) % increment) : increment;
+        cal.add(type, interval);
+    }
+
+    /**
+     * Format file name.
+     * @param buf string buffer to which formatted file name is appended, may not be null.
+     * @param obj object to be evaluated in formatting, may not be null.
+     */
+    public final void formatFileName(final StringBuilder buf, final Object obj) {
+        final long time = prevFileTime == 0 ? System.currentTimeMillis() : prevFileTime;
+        formatFileName(buf, new Date(time), obj);
+    }
+
+    /**
+     * Formats file name.
+     * @param subst The StrSubstitutor.
+     * @param buf string buffer to which formatted file name is appended, may not be null.
+     * @param obj object to be evaluated in formatting, may not be null.
+     */
+    public final void formatFileName(final StrSubstitutor subst, final StringBuilder buf, final Object obj) {
+        // LOG4J2-628: we deliberately use System time, not the log4j.Clock time
+        // for creating the file name of rolled-over files. 
+        final long time = prevFileTime == 0 ? System.currentTimeMillis() : prevFileTime;
+        formatFileName(buf, new Date(time), obj);
+        final LogEvent event = new Log4jLogEvent.Builder().setTimeMillis(time).build();
+        final String fileName = subst.replace(event, buf);
+        buf.setLength(0);
+        buf.append(fileName);
+    }
+
+    /**
+     * Formats file name.
+     * @param buf string buffer to which formatted file name is appended, may not be null.
+     * @param objects objects to be evaluated in formatting, may not be null.
+     */
+    protected final void formatFileName(final StringBuilder buf, final Object... objects) {
+        for (int i = 0; i < patternConverters.length; i++) {
+            final int fieldStart = buf.length();
+            patternConverters[i].format(buf, objects);
+
+            if (patternFields[i] != null) {
+                patternFields[i].format(fieldStart, buf);
+            }
+        }
+    }
+
+    private RolloverFrequency calculateFrequency(final String pattern) {
+        if (patternContains(pattern, MILLIS_CHAR)) {
+            return RolloverFrequency.EVERY_MILLISECOND;
+        }
+        if (patternContains(pattern, SECOND_CHAR)) {
+            return RolloverFrequency.EVERY_SECOND;
+        }
+        if (patternContains(pattern, MINUTE_CHAR)) {
+            return RolloverFrequency.EVERY_MINUTE;
+        }
+        if (patternContains(pattern, HOUR_CHARS)) {
+            return RolloverFrequency.HOURLY;
+        }
+        if (patternContains(pattern, DAY_CHARS)) {
+            return RolloverFrequency.DAILY;
+        }
+        if (patternContains(pattern, WEEK_CHARS)) {
+            return RolloverFrequency.WEEKLY;
+        }
+        if (patternContains(pattern, MONTH_CHAR)) {
+            return RolloverFrequency.MONTHLY;
+        }
+        if (patternContains(pattern, YEAR_CHAR)) {
+            return RolloverFrequency.ANNUALLY;
+        }
+        return null;
+    }
+
+    private PatternParser createPatternParser() {
+
+        return new PatternParser(null, KEY, null);
+    }
+
+    private boolean patternContains(final String pattern, final char... chars) {
+        for (final char character : chars) {
+            if (patternContains(pattern, character)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private boolean patternContains(final String pattern, final char character) {
+        return pattern.indexOf(character) >= 0;
+    }
+
+    public RolloverFrequency getFrequency() {
+        return frequency;
+    }
+
+    public long getNextFileTime() {
+        return nextFileTime;
+    }
+}


[02/11] logging-log4j2 git commit: Alias "tn" for "threadName" for consistency with other thread converters.

Posted by rp...@apache.org.
Alias "tn" for "threadName" for consistency with other thread
converters.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/216d52ef
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/216d52ef
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/216d52ef

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 216d52efe99e58e86f36584768897458c5944683
Parents: 20be2b0
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 22 18:14:28 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 22 18:14:28 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/pattern/ThreadNamePatternConverter.java     | 2 +-
 src/site/xdoc/manual/layouts.xml.vm                                | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/216d52ef/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadNamePatternConverter.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadNamePatternConverter.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadNamePatternConverter.java
index 37c0861..8336e88 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadNamePatternConverter.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/ThreadNamePatternConverter.java
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.core.config.plugins.Plugin;
  * Formats the event thread name.
  */
 @Plugin(name = "ThreadPatternConverter", category = PatternConverter.CATEGORY)
-@ConverterKeys({ "t", "thread", "threadName" })
+@ConverterKeys({ "t", "tn", "thread", "threadName" })
 public final class ThreadNamePatternConverter extends LogEventPatternConverter {
     /**
      * Singleton.

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/216d52ef/src/site/xdoc/manual/layouts.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/layouts.xml.vm b/src/site/xdoc/manual/layouts.xml.vm
index d193380..31ac6bd 100644
--- a/src/site/xdoc/manual/layouts.xml.vm
+++ b/src/site/xdoc/manual/layouts.xml.vm
@@ -1280,6 +1280,7 @@ WARN  [main]: Message 2</pre>
               <td align="center">
                 <a name="PatternThreadName"/>
                 <b>t</b><br />
+                <b>tn</b><br />
                 <b>thread</b><br />
                 <b>threadName</b>
               </td>


[06/11] logging-log4j2 git commit: Remove obsolete link

Posted by rp...@apache.org.
Remove obsolete link


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/6b8db31c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/6b8db31c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/6b8db31c

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 6b8db31c92391019a6f681b046fc67a2ae390f8e
Parents: 1385924
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed Mar 23 14:51:19 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed Mar 23 14:51:19 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/logging/log4j/core/layout/GelfLayout.java  | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/6b8db31c/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index 7942ebb..cb471a3 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -66,7 +66,6 @@ import com.fasterxml.jackson.core.io.JsonStringEncoder;
  * &lt;/Appenders&gt;
  * </pre>
  *
- * @see <a href="http://graylog2.org/gelf">GELF home page</a>
  * @see <a href="http://graylog2.org/resources/gelf/specification">GELF
  *      specification</a>
  */


[09/11] logging-log4j2 git commit: Allocation free formatTimestamp

Posted by rp...@apache.org.
Allocation free formatTimestamp


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f41322b4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f41322b4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f41322b4

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: f41322b493cf5e705c25ed720f53bf937f47fcbc
Parents: 0b77d16
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed Mar 23 17:17:58 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed Mar 23 17:17:58 2016 +0100

----------------------------------------------------------------------
 .../logging/log4j/core/layout/GelfLayout.java   | 42 +++++++++++++-------
 .../log4j/core/layout/GelfLayoutTest.java       |  4 ++
 2 files changed, 32 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f41322b4/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index 6d247c2..da28935 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -16,18 +16,7 @@
  */
 package org.apache.logging.log4j.core.layout;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.math.BigDecimal;
-import java.nio.charset.StandardCharsets;
-import java.util.Collections;
-import java.util.Map;
-import java.util.zip.DeflaterOutputStream;
-import java.util.zip.GZIPOutputStream;
-
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
@@ -42,7 +31,13 @@ import org.apache.logging.log4j.core.util.KeyValuePair;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.Strings;
 
-import com.fasterxml.jackson.core.io.JsonStringEncoder;
+import java.io.*;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Map;
+import java.util.zip.DeflaterOutputStream;
+import java.util.zip.GZIPOutputStream;
 
 /**
  * Lays out events in the Graylog Extended Log Format (GELF) 1.1.
@@ -222,7 +217,26 @@ public final class GelfLayout extends AbstractStringLayout {
      * Non-private to make it accessible from unit test.
      */
     static CharSequence formatTimestamp(final long timeMillis) {
-        return new BigDecimal(timeMillis).divide(TIME_DIVISOR).toPlainString();
+        if (timeMillis < 1000) {
+            return "0";
+        } else {
+            StringBuilder builder = getTimestampStringBuilder();
+            builder.append(timeMillis);
+            builder.insert(builder.length() - 3, '.');
+            return builder;
+        }
+    }
+
+    private static final ThreadLocal<StringBuilder> timestampStringBuilder = new ThreadLocal<>();
+
+    private static StringBuilder getTimestampStringBuilder() {
+        StringBuilder result = timestampStringBuilder.get();
+        if (result == null) {
+            result = new StringBuilder(20);
+            timestampStringBuilder.set(result);
+        }
+        result.setLength(0);
+        return result;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f41322b4/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
index c89fad9..d3e66d6 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
@@ -214,6 +214,10 @@ public class GelfLayoutTest {
     @Test
     public void testFormatTimestamp() {
         assertEquals("0", GelfLayout.formatTimestamp(0L).toString());
+        assertEquals("1.000", GelfLayout.formatTimestamp(1000L).toString());
+        assertEquals("1.001", GelfLayout.formatTimestamp(1001L).toString());
+        assertEquals("1.010", GelfLayout.formatTimestamp(1010L).toString());
+        assertEquals("1.100", GelfLayout.formatTimestamp(1100L).toString());
         assertEquals("1458741206.653", GelfLayout.formatTimestamp(1458741206653L).toString());
         assertEquals("9223372036854775.807", GelfLayout.formatTimestamp(Long.MAX_VALUE).toString());
     }


[08/11] logging-log4j2 git commit: Unit test for formatTimestamp

Posted by rp...@apache.org.
Unit test for formatTimestamp


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0b77d16d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0b77d16d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0b77d16d

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 0b77d16dc17cf435243b7f4bb9abc7e7e3ea0ec1
Parents: 0623673
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed Mar 23 15:27:09 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed Mar 23 15:27:09 2016 +0100

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/layout/GelfLayoutTest.java | 8 ++++++++
 1 file changed, 8 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0b77d16d/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
index c82fa21..c89fad9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/layout/GelfLayoutTest.java
@@ -38,6 +38,7 @@ import java.util.zip.GZIPInputStream;
 import java.util.zip.InflaterInputStream;
 
 import static net.javacrumbs.jsonunit.JsonAssert.assertJsonEquals;
+import static org.junit.Assert.assertEquals;
 
 public class GelfLayoutTest {
     static ConfigurationFactory configFactory = new BasicConfigurationFactory();
@@ -209,4 +210,11 @@ public class GelfLayoutTest {
     public void testLayoutZlibCompression() throws Exception {
         testCompressedLayout(CompressionType.ZLIB);
     }
+
+    @Test
+    public void testFormatTimestamp() {
+        assertEquals("0", GelfLayout.formatTimestamp(0L).toString());
+        assertEquals("1458741206.653", GelfLayout.formatTimestamp(1458741206653L).toString());
+        assertEquals("9223372036854775.807", GelfLayout.formatTimestamp(Long.MAX_VALUE).toString());
+    }
 }


[04/11] logging-log4j2 git commit: https://issues.apache.org/jira/browse/LOG4J2-1323 - Make life a little easier for advanced users.

Posted by rp...@apache.org.
https://issues.apache.org/jira/browse/LOG4J2-1323 - Make life a little
easier for advanced users.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/80cc8335
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/80cc8335
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/80cc8335

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 80cc8335e2ab2380a823b978cb4fb3302fa39289
Parents: 250f720
Author: ggregory <gg...@apache.org>
Authored: Tue Mar 22 18:19:21 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Mar 22 18:19:21 2016 -0700

----------------------------------------------------------------------
 .../apache/logging/log4j/core/appender/DefaultErrorHandler.java  | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/80cc8335/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/DefaultErrorHandler.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/DefaultErrorHandler.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/DefaultErrorHandler.java
index ceade7f..fa51b95 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/DefaultErrorHandler.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/DefaultErrorHandler.java
@@ -93,4 +93,8 @@ public class DefaultErrorHandler implements ErrorHandler {
             throw new AppenderLoggingException(msg, t);
         }
     }
+
+    public Appender getAppender() {
+        return appender;
+    }
 }


[07/11] logging-log4j2 git commit: Prepare GC free

Posted by rp...@apache.org.
Prepare GC free


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/06236739
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/06236739
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/06236739

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 062367394dcac65a86fe98b507359aab03ea1308
Parents: 6b8db31
Author: Mikael Ståldal <mi...@magine.com>
Authored: Wed Mar 23 15:26:15 2016 +0100
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Wed Mar 23 15:26:15 2016 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/logging/log4j/core/layout/GelfLayout.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/06236739/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
index cb471a3..6d247c2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/GelfLayout.java
@@ -221,7 +221,7 @@ public final class GelfLayout extends AbstractStringLayout {
     /**
      * Non-private to make it accessible from unit test.
      */
-    static String formatTimestamp(final long timeMillis) {
+    static CharSequence formatTimestamp(final long timeMillis) {
         return new BigDecimal(timeMillis).divide(TIME_DIVISOR).toPlainString();
     }
 


[11/11] logging-log4j2 git commit: Merge remote-tracking branch 'remotes/origin/master' into LOG4J2-1278-gc-free-logger

Posted by rp...@apache.org.
Merge remote-tracking branch 'remotes/origin/master' into LOG4J2-1278-gc-free-logger


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5a873ddf
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5a873ddf
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5a873ddf

Branch: refs/heads/LOG4J2-1278-gc-free-logger
Commit: 5a873ddf0898efdf637b9abcea2facd2aa126ad2
Parents: d3e3947 29a4e87
Author: rpopma <rp...@apache.org>
Authored: Fri Mar 25 01:16:05 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Mar 25 01:16:05 2016 +0900

----------------------------------------------------------------------
 .../core/appender/DefaultErrorHandler.java      |   4 +
 .../core/appender/rolling/PatternProcessor.java | 581 ++++++++++---------
 .../log4j/core/async/RingBufferLogEvent.java    |  99 ++--
 .../logging/log4j/core/layout/GelfLayout.java   |  45 +-
 .../pattern/ThreadNamePatternConverter.java     |   2 +-
 .../logging/log4j/core/GcFreeLoggingTest.java   |   6 +-
 .../log4j/core/layout/GelfLayoutTest.java       |  12 +
 log4j-core/src/test/resources/gcFreeLogging.xml |  19 +
 src/site/xdoc/manual/layouts.xml.vm             |   1 +
 9 files changed, 414 insertions(+), 355 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5a873ddf/log4j-core/src/test/java/org/apache/logging/log4j/core/GcFreeLoggingTest.java
----------------------------------------------------------------------