You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/18 13:38:00 UTC

[14/50] logging-log4j2 git commit: LOG4J2-1334 moved two constants from RingBufferLogEvent to Constants so they can be used in MutableLogEvent

LOG4J2-1334 moved two constants from RingBufferLogEvent to Constants so they can be used in MutableLogEvent


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

Branch: refs/heads/LOG4J2-1365
Commit: 7cbc43fedda1bd69101282c87ba167aecf2a99f5
Parents: 2468c8c
Author: rpopma <rp...@apache.org>
Authored: Sun Apr 17 14:32:01 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Apr 17 14:32:01 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/async/RingBufferLogEvent.java        | 15 ++++-----------
 .../apache/logging/log4j/core/util/Constants.java   | 16 +++++++++++++++-
 2 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7cbc43fe/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 f3ad22f..6929596 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
@@ -33,7 +33,6 @@ import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ReusableMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
 import org.apache.logging.log4j.message.TimestampMessage;
-import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.Strings;
 
 import com.lmax.disruptor.EventFactory;
@@ -48,15 +47,9 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
     public static final Factory FACTORY = new Factory();
 
     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);
-    }
-
     /**
      * Creates the events that will be put in the RingBuffer.
      */
@@ -66,7 +59,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
         public RingBufferLogEvent newInstance() {
             RingBufferLogEvent result = new RingBufferLogEvent();
             if (Constants.ENABLE_THREADLOCALS) {
-                result.messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
+                result.messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
             }
             return result;
         }
@@ -130,7 +123,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
         if (messageText == null) {
             // Should never happen:
             // only happens if user logs a custom reused message when Constants.ENABLE_THREADLOCALS is false
-            messageText = new StringBuilder(INITIAL_REUSABLE_MESSAGE_SIZE);
+            messageText = new StringBuilder(Constants.INITIAL_REUSABLE_MESSAGE_SIZE);
         }
         messageText.setLength(0);
         return messageText;
@@ -356,8 +349,8 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
 
     // ensure that excessively long char[] arrays are not kept in memory forever
     private void trimMessageText() {
-        if (messageText != null && messageText.length() > MAX_REUSABLE_MESSAGE_SIZE) {
-            messageText.setLength(MAX_REUSABLE_MESSAGE_SIZE);
+        if (messageText != null && messageText.length() > Constants.MAX_REUSABLE_MESSAGE_SIZE) {
+            messageText.setLength(Constants.MAX_REUSABLE_MESSAGE_SIZE);
             messageText.trimToSize();
         }
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7cbc43fe/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
index 54e0a86..95bd03e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/util/Constants.java
@@ -19,7 +19,6 @@ package org.apache.logging.log4j.core.util;
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 
-import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
@@ -108,6 +107,21 @@ public final class Constants {
             //AsyncLoggerContextSelector.class.getName().equals(PropertiesUtil.getProperties().getStringProperty(LOG4J_CONTEXT_SELECTOR)));
 
     /**
+     * Initial StringBuilder size used in RingBuffer LogEvents to store the contents of reusable Messages.
+     */
+    public static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
+
+    /**
+     * Maximum size of the StringBuilders used in RingBuffer LogEvents to store the contents of reusable Messages.
+     * After a large message has been delivered to the appenders, the StringBuilder is trimmed to this size.
+     */
+    public static final int MAX_REUSABLE_MESSAGE_SIZE = size("log4j.maxReusableMsgSize", (128 * 2 + 2) * 2 + 2);
+
+    private static int size(final String property, final int defaultValue) {
+        return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue);
+    }
+
+    /**
      * Prevent class instantiation.
      */
     private Constants() {