logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: logging-log4j2 git commit: LOG4J2-1437 ObjectMessage and ReusableObjectMessage now avoid calling toString() on auto-boxed primitive parameters
Date Sun, 19 Jun 2016 06:08:23 GMT
That said, we do have duplicate code in three places now and should
probably factor this out to some utility method.

On Sunday, 19 June 2016, Remko Popma <remko.popma@gmail.com> wrote:

> I thought Anthony did performance tests for this and this was the fastest
> way to do it.
>
> On Sun, Jun 19, 2016 at 1:18 PM, Gary Gregory <garydgregory@gmail.com
> <javascript:_e(%7B%7D,'cvml','garydgregory@gmail.com');>> wrote:
>
>> Wow, I do not like these cascading if elses but there is no way around it
>> unless we go through many hoops. Like a map from class to... a closure,
>> Java 8 or 7.
>>
>> Gary
>> ---------- Forwarded message ----------
>> From: <rpopma@apache.org
>> <javascript:_e(%7B%7D,'cvml','rpopma@apache.org');>>
>> Date: Jun 18, 2016 8:55 PM
>> Subject: logging-log4j2 git commit: LOG4J2-1437 ObjectMessage and
>> ReusableObjectMessage now avoid calling toString() on auto-boxed primitive
>> parameters
>> To: <commits@logging.apache.org
>> <javascript:_e(%7B%7D,'cvml','commits@logging.apache.org');>>
>> Cc:
>>
>> Repository: logging-log4j2
>>> Updated Branches:
>>>   refs/heads/master 6eff4fc46 -> b225685f3
>>>
>>>
>>> LOG4J2-1437  ObjectMessage and ReusableObjectMessage now avoid calling
>>> toString() on auto-boxed primitive parameters
>>>
>>>
>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>> Commit:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/b225685f
>>> Tree:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/b225685f
>>> Diff:
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/b225685f
>>>
>>> Branch: refs/heads/master
>>> Commit: b225685f30b08229b29a64c91d4e29d06a1724ee
>>> Parents: 6eff4fc
>>> Author: rpopma <rpopma@apache.org
>>> <javascript:_e(%7B%7D,'cvml','rpopma@apache.org');>>
>>> Authored: Sun Jun 19 12:55:22 2016 +0900
>>> Committer: rpopma <rpopma@apache.org
>>> <javascript:_e(%7B%7D,'cvml','rpopma@apache.org');>>
>>> Committed: Sun Jun 19 12:55:22 2016 +0900
>>>
>>> ----------------------------------------------------------------------
>>>  .../apache/logging/log4j/message/ObjectMessage.java   | 14
>>> ++++++++++++++
>>>  .../logging/log4j/message/ReusableObjectMessage.java  | 14
>>> ++++++++++++++
>>>  src/changes/changes.xml                               |  3 +++
>>>  3 files changed, 31 insertions(+)
>>> ----------------------------------------------------------------------
>>>
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b225685f/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
>>> b/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
>>> index db8c31b..7ab9a48 100644
>>> ---
>>> a/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
>>> +++
>>> b/log4j-api/src/main/java/org/apache/logging/log4j/message/ObjectMessage.java
>>> @@ -64,6 +64,20 @@ public class ObjectMessage implements Message,
>>> StringBuilderFormattable {
>>>              ((StringBuilderFormattable) obj).formatTo(buffer);
>>>          } else if (obj instanceof CharSequence) {
>>>              buffer.append((CharSequence) obj);
>>> +        } else if (obj instanceof Integer) { // LOG4J2-1437 unbox
>>> auto-boxed primitives to avoid calling toString()
>>> +            buffer.append(((Integer) obj).intValue());
>>> +        } else if (obj instanceof Long) {
>>> +            buffer.append(((Long) obj).longValue());
>>> +        } else if (obj instanceof Double) {
>>> +            buffer.append(((Double) obj).doubleValue());
>>> +        } else if (obj instanceof Boolean) {
>>> +            buffer.append(((Boolean) obj).booleanValue());
>>> +        } else if (obj instanceof Character) {
>>> +            buffer.append(((Character) obj).charValue());
>>> +        } else if (obj instanceof Short) {
>>> +            buffer.append(((Short) obj).shortValue());
>>> +        } else if (obj instanceof Float) {
>>> +            buffer.append(((Float) obj).floatValue());
>>>          } else {
>>>              buffer.append(obj);
>>>          }
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b225685f/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
>>> ----------------------------------------------------------------------
>>> diff --git
>>> a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
>>> b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
>>> index 21e9f98..fb3f176 100644
>>> ---
>>> a/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
>>> +++
>>> b/log4j-api/src/main/java/org/apache/logging/log4j/message/ReusableObjectMessage.java
>>> @@ -52,6 +52,20 @@ public class ReusableObjectMessage implements
>>> ReusableMessage {
>>>              ((StringBuilderFormattable) obj).formatTo(buffer);
>>>          } else if (obj instanceof CharSequence) {
>>>              buffer.append((CharSequence) obj);
>>> +        } else if (obj instanceof Integer) { // LOG4J2-1437 unbox
>>> auto-boxed primitives to avoid calling toString()
>>> +            buffer.append(((Integer) obj).intValue());
>>> +        } else if (obj instanceof Long) {
>>> +            buffer.append(((Long) obj).longValue());
>>> +        } else if (obj instanceof Double) {
>>> +            buffer.append(((Double) obj).doubleValue());
>>> +        } else if (obj instanceof Boolean) {
>>> +            buffer.append(((Boolean) obj).booleanValue());
>>> +        } else if (obj instanceof Character) {
>>> +            buffer.append(((Character) obj).charValue());
>>> +        } else if (obj instanceof Short) {
>>> +            buffer.append(((Short) obj).shortValue());
>>> +        } else if (obj instanceof Float) {
>>> +            buffer.append(((Float) obj).floatValue());
>>>          } else {
>>>              buffer.append(obj);
>>>          }
>>>
>>>
>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b225685f/src/changes/changes.xml
>>> ----------------------------------------------------------------------
>>> diff --git a/src/changes/changes.xml b/src/changes/changes.xml
>>> index 84ff494..7f5eeaa 100644
>>> --- a/src/changes/changes.xml
>>> +++ b/src/changes/changes.xml
>>> @@ -43,6 +43,9 @@
>>>        <action issue="LOG4J2-1422" dev="rpopma" type="fix">
>>>          Fixed issue where AsyncAppenderQueueFullPolicyTest sometimes
>>> hangs.
>>>        </action>
>>> +      <action issue="LOG4J2-1437" dev="rpopma" type="add">
>>> +        (GC) ObjectMessage and ReusableObjectMessage now avoid calling
>>> toString() on auto-boxed primitive parameters.
>>> +      </action>
>>>        <action issue="LOG4J2-1415" dev="rpopma" type="add">
>>>          (GC) ParameterFormatter now avoids calling toString() on
>>> auto-boxed primitive message parameters.
>>>        </action>
>>>
>>>
>

Mime
View raw message