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/04/16 14:55:00 UTC

[1/5] logging-log4j2 git commit: LOG4J2-1334 ReusableLogEventFactory various fixes

Repository: logging-log4j2
Updated Branches:
  refs/heads/master adcdfc0e2 -> 328a8bf8f


LOG4J2-1334 ReusableLogEventFactory various fixes


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

Branch: refs/heads/master
Commit: dc9b6afe0c3b46d57f88671802134574d6b530fa
Parents: adcdfc0
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:39:22 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:39:22 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/impl/ReusableLogEventFactory.java       | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/dc9b6afe/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
index 190b27a..2912d91 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ReusableLogEventFactory.java
@@ -24,11 +24,13 @@ import org.apache.logging.log4j.core.config.Property;
 import org.apache.logging.log4j.core.util.Clock;
 import org.apache.logging.log4j.core.util.ClockFactory;
 import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.TimestampMessage;
 
 import java.util.List;
 
 /**
  * Garbage-free LogEventFactory that reuses a single mutable log event.
+ * @since 2.6
  */
 public class ReusableLogEventFactory implements LogEventFactory {
 
@@ -41,14 +43,14 @@ public class ReusableLogEventFactory implements LogEventFactory {
      * @param marker An optional Marker.
      * @param fqcn The fully qualified class name of the caller.
      * @param level The event Level.
-     * @param data The Message.
+     * @param message The Message.
      * @param properties Properties to be added to the log event.
      * @param t An optional Throwable.
      * @return The LogEvent.
      */
     @Override
     public LogEvent createEvent(final String loggerName, final Marker marker,
-                                final String fqcn, final Level level, final Message data,
+                                final String fqcn, final Level level, final Message message,
                                 final List<Property> properties, final Throwable t) {
         MutableLogEvent result = mutableLogEventThreadLocal.get();
         if (result == null) {
@@ -58,16 +60,19 @@ public class ReusableLogEventFactory implements LogEventFactory {
             result.setThreadPriority(Thread.currentThread().getPriority());
             mutableLogEventThreadLocal.set(result);
         }
+        result.clear();
 
         result.setLoggerName(loggerName);
         result.setMarker(marker);
         result.setLoggerFqcn(fqcn);
         result.setLevel(level == null ? Level.OFF : level);
-        result.setMessage(data);
+        result.setMessage(message);
         result.setThrown(t);
         result.setContextMap(Log4jLogEvent.createMap(properties));
         result.setContextStack(ThreadContext.getDepth() == 0 ? null : ThreadContext.cloneStack());// mutable copy
-        result.setTimeMillis(CLOCK.currentTimeMillis());
+        result.setTimeMillis(message instanceof TimestampMessage
+                ? ((TimestampMessage) message).getTimestamp()
+                : CLOCK.currentTimeMillis());
         result.setNanoTime(Log4jLogEvent.getNanoClock().nanoTime());
 
         // TODO


[5/5] logging-log4j2 git commit: LOG4J2-1334 the kill switch for MutableLogEvents (currently short-circuited so it always uses Log4jLogEvent)

Posted by rp...@apache.org.
LOG4J2-1334 the kill switch for MutableLogEvents (currently short-circuited so it always uses Log4jLogEvent)


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

Branch: refs/heads/master
Commit: 328a8bf8f0d80b466d2d5c666c9f7a31d70ba678
Parents: cedf155
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:52:39 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:52:39 2016 +0900

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/core/config/LoggerConfig.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/328a8bf8/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
index e5eb9d4..7b030c6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/LoggerConfig.java
@@ -40,6 +40,7 @@ import org.apache.logging.log4j.core.filter.AbstractFilterable;
 import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
 import org.apache.logging.log4j.core.impl.Log4jLogEvent;
 import org.apache.logging.log4j.core.impl.LogEventFactory;
+import org.apache.logging.log4j.core.impl.ReusableLogEventFactory;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.core.util.Booleans;
 import org.apache.logging.log4j.core.util.Constants;
@@ -83,7 +84,9 @@ public class LoggerConfig extends AbstractFilterable {
             }
         }
         if (LOG_EVENT_FACTORY == null) {
-            LOG_EVENT_FACTORY = new DefaultLogEventFactory();
+            LOG_EVENT_FACTORY = false //Constants.ENABLE_THREADLOCALS
+                    ? new ReusableLogEventFactory()
+                    : new DefaultLogEventFactory();
         }
     }
 


Re: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by Remko Popma <re...@gmail.com>.
I hadn't thought of that. In this case though not all attributes are immutable so going through Log4jLogEvent.Proxy may be prudent. (In spite of the name, Java io serialization is not involved here. )

Sent from my iPhone

> On 2016/04/18, at 19:54, Mikael Ståldal <mi...@magine.com> wrote:
> 
> Isn't this what clone() should be used for?
> 
>> On Sat, Apr 16, 2016 at 10:51 PM, Remko Popma <re...@gmail.com> wrote:
>> Makes sense. 
>> 
>> Sent from my iPhone
>> 
>>> On 2016/04/16, at 23:20, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> Hi,
>>> 
>>> The ser+deser sequence feels like something that should be refactored into a serializedCopy() or deepCopy() method depending on whether or not you want to publicize the copying technique.
>>> 
>>> Gary
>>> 
>>> ---------- Forwarded message ----------
>>> From: <rp...@apache.org>
>>> Date: Apr 16, 2016 5:55 AM
>>> Subject: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)
>>> To: <co...@logging.apache.org>
>>> Cc: 
>>> 
>>>> LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)
>>>> 
>>>> 
>>>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>>>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3f395f63
>>>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3f395f63
>>>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3f395f63
>>>> 
>>>> Branch: refs/heads/master
>>>> Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
>>>> Parents: 07cd44a
>>>> Author: rpopma <rp...@apache.org>
>>>> Authored: Sat Apr 16 21:41:40 2016 +0900
>>>> Committer: rpopma <rp...@apache.org>
>>>> Committed: Sat Apr 16 21:41:40 2016 +0900
>>>> 
>>>> ----------------------------------------------------------------------
>>>>  .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
>>>>  1 file changed, 8 insertions(+), 1 deletion(-)
>>>> ----------------------------------------------------------------------
>>>> 
>>>> 
>>>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>>>> ----------------------------------------------------------------------
>>>> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>>>> index 97ca15d..19aeaee 100644
>>>> --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>>>> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>>>> @@ -31,6 +31,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>>>>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>>>  import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
>>>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>>>> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>>>>  import org.apache.logging.log4j.core.layout.SerializedLayout;
>>>> 
>>>>  /**
>>>> @@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
>>>>      public synchronized void append(final LogEvent event) {
>>>>          final Layout<? extends Serializable> layout = getLayout();
>>>>          if (layout == null) {
>>>> -            events.add(event);
>>>> +            if (event instanceof MutableLogEvent) {
>>>> +                // must take snapshot or subsequent calls to logger.log() will modify this event
>>>> +                events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation())));
>>>> +            } else {
>>>> +                events.add(event);
>>>> +            }
>>>>          } else if (layout instanceof SerializedLayout) {
>>>>              final byte[] header = layout.getHeader();
>>>>              final byte[] content = layout.toByteArray(event);
> 
> 
> 
> -- 
>  
> 
> Mikael Ståldal
> Senior software developer 
> 
> Magine TV
> mikael.staldal@magine.com    
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com             
> 
> Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, 
> you should destroy this message and kindly notify the sender by reply email.   

Re: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by Mikael Ståldal <mi...@magine.com>.
Isn't this what clone() should be used for?

On Sat, Apr 16, 2016 at 10:51 PM, Remko Popma <re...@gmail.com> wrote:

> Makes sense.
>
> Sent from my iPhone
>
> On 2016/04/16, at 23:20, Gary Gregory <ga...@gmail.com> wrote:
>
> Hi,
>
> The ser+deser sequence feels like something that should be refactored into
> a serializedCopy() or deepCopy() method depending on whether or not you
> want to publicize the copying technique.
>
> Gary
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: Apr 16, 2016 5:55 AM
> Subject: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must
> add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself
> (since it will change)
> To: <co...@logging.apache.org>
> Cc:
>
> LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list,
>> not the MutableLogEvent itself (since it will change)
>>
>>
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit:
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3f395f63
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3f395f63
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3f395f63
>>
>> Branch: refs/heads/master
>> Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
>> Parents: 07cd44a
>> Author: rpopma <rp...@apache.org>
>> Authored: Sat Apr 16 21:41:40 2016 +0900
>> Committer: rpopma <rp...@apache.org>
>> Committed: Sat Apr 16 21:41:40 2016 +0900
>>
>> ----------------------------------------------------------------------
>>  .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>> ----------------------------------------------------------------------
>>
>>
>>
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> ----------------------------------------------------------------------
>> diff --git
>> a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> index 97ca15d..19aeaee 100644
>> ---
>> a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> +++
>> b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> @@ -31,6 +31,8 @@ import
>> org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>  import
>> org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>>  import org.apache.logging.log4j.core.layout.SerializedLayout;
>>
>>  /**
>> @@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
>>      public synchronized void append(final LogEvent event) {
>>          final Layout<? extends Serializable> layout = getLayout();
>>          if (layout == null) {
>> -            events.add(event);
>> +            if (event instanceof MutableLogEvent) {
>> +                // must take snapshot or subsequent calls to
>> logger.log() will modify this event
>> +
>> events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event,
>> event.isIncludeLocation())));
>> +            } else {
>> +                events.add(event);
>> +            }
>>          } else if (layout instanceof SerializedLayout) {
>>              final byte[] header = layout.getHeader();
>>              final byte[] content = layout.toByteArray(event);
>>
>>


-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by Remko Popma <re...@gmail.com>.
Makes sense. 

Sent from my iPhone

> On 2016/04/16, at 23:20, Gary Gregory <ga...@gmail.com> wrote:
> 
> Hi,
> 
> The ser+deser sequence feels like something that should be refactored into a serializedCopy() or deepCopy() method depending on whether or not you want to publicize the copying technique.
> 
> Gary
> 
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: Apr 16, 2016 5:55 AM
> Subject: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)
> To: <co...@logging.apache.org>
> Cc: 
> 
>> LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)
>> 
>> 
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3f395f63
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3f395f63
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3f395f63
>> 
>> Branch: refs/heads/master
>> Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
>> Parents: 07cd44a
>> Author: rpopma <rp...@apache.org>
>> Authored: Sat Apr 16 21:41:40 2016 +0900
>> Committer: rpopma <rp...@apache.org>
>> Committed: Sat Apr 16 21:41:40 2016 +0900
>> 
>> ----------------------------------------------------------------------
>>  .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
>>  1 file changed, 8 insertions(+), 1 deletion(-)
>> ----------------------------------------------------------------------
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> index 97ca15d..19aeaee 100644
>> --- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> +++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
>> @@ -31,6 +31,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>>  import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
>> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
>> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>>  import org.apache.logging.log4j.core.layout.SerializedLayout;
>> 
>>  /**
>> @@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
>>      public synchronized void append(final LogEvent event) {
>>          final Layout<? extends Serializable> layout = getLayout();
>>          if (layout == null) {
>> -            events.add(event);
>> +            if (event instanceof MutableLogEvent) {
>> +                // must take snapshot or subsequent calls to logger.log() will modify this event
>> +                events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation())));
>> +            } else {
>> +                events.add(event);
>> +            }
>>          } else if (layout instanceof SerializedLayout) {
>>              final byte[] header = layout.getHeader();
>>              final byte[] content = layout.toByteArray(event);

Fwd: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by Gary Gregory <ga...@gmail.com>.
Hi,

The ser+deser sequence feels like something that should be refactored into
a serializedCopy() or deepCopy() method depending on whether or not you
want to publicize the copying technique.

Gary
---------- Forwarded message ----------
From: <rp...@apache.org>
Date: Apr 16, 2016 5:55 AM
Subject: [3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add
snapshot of MutableLogEvent to the list, not the MutableLogEvent itself
(since it will change)
To: <co...@logging.apache.org>
Cc:

LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list,
> not the MutableLogEvent itself (since it will change)
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3f395f63
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3f395f63
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3f395f63
>
> Branch: refs/heads/master
> Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
> Parents: 07cd44a
> Author: rpopma <rp...@apache.org>
> Authored: Sat Apr 16 21:41:40 2016 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Sat Apr 16 21:41:40 2016 +0900
>
> ----------------------------------------------------------------------
>  .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
> ----------------------------------------------------------------------
> diff --git
> a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
> b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
> index 97ca15d..19aeaee 100644
> ---
> a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
> +++
> b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
> @@ -31,6 +31,8 @@ import
> org.apache.logging.log4j.core.config.plugins.PluginAttribute;
>  import org.apache.logging.log4j.core.config.plugins.PluginElement;
>  import org.apache.logging.log4j.core.config.plugins.PluginFactory;
>  import
> org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>  import org.apache.logging.log4j.core.layout.SerializedLayout;
>
>  /**
> @@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
>      public synchronized void append(final LogEvent event) {
>          final Layout<? extends Serializable> layout = getLayout();
>          if (layout == null) {
> -            events.add(event);
> +            if (event instanceof MutableLogEvent) {
> +                // must take snapshot or subsequent calls to logger.log()
> will modify this event
> +
> events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event,
> event.isIncludeLocation())));
> +            } else {
> +                events.add(event);
> +            }
>          } else if (layout instanceof SerializedLayout) {
>              final byte[] header = layout.getHeader();
>              final byte[] content = layout.toByteArray(event);
>
>

[3/5] logging-log4j2 git commit: LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)

Posted by rp...@apache.org.
LOG4J2-1334 ListAppender must add snapshot of MutableLogEvent to the list, not the MutableLogEvent itself (since it will change)


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

Branch: refs/heads/master
Commit: 3f395f63d03b603ef628e214d3f01dd226793baf
Parents: 07cd44a
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:41:40 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:41:40 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/test/appender/ListAppender.java    | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3f395f63/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
index 97ca15d..19aeaee 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/test/appender/ListAppender.java
@@ -31,6 +31,8 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute;
 import org.apache.logging.log4j.core.config.plugins.PluginElement;
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.layout.SerializedLayout;
 
 /**
@@ -81,7 +83,12 @@ public class ListAppender extends AbstractAppender {
     public synchronized void append(final LogEvent event) {
         final Layout<? extends Serializable> layout = getLayout();
         if (layout == null) {
-            events.add(event);
+            if (event instanceof MutableLogEvent) {
+                // must take snapshot or subsequent calls to logger.log() will modify this event
+                events.add(Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation())));
+            } else {
+                events.add(event);
+            }
         } else if (layout instanceof SerializedLayout) {
             final byte[] header = layout.getHeader();
             final byte[] content = layout.toByteArray(event);


Re: [2/5] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name

Posted by Remko Popma <re...@gmail.com>.
You are right. Unit tests are on the way. I started with fixing the issues brought to light by the existing unit tests, but I still need to add tests for MutableLogEvent and its factory. 

About that comment: thread name is initialized once by the factory when the MutableLogEvent is created and stored in a ThreadLocal. It should not be cleared because it may not be set again (still need to implement ThreadName strategy in the factory, but the default is to set it only once).



Sent from my iPhone

> On 2016/04/16, at 23:26, Gary Gregory <ga...@gmail.com> wrote:
> 
> 1) I'm seeing some commits fly by sans unit tests. Are setting our selves up for regressions?
> 
> 2) Also, better comments would help (me). For example, this comments states" THreadName should not be cleared" but why?
> 
> 3) Typo in capitalization: THreadName
> 
> Gary
> 
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: Apr 16, 2016 5:55 AM
> Subject: [2/5] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name
> To: <co...@logging.apache.org>
> Cc: 
> 
>> LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name
>> 
>> 
>> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07cd44a0
>> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07cd44a0
>> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07cd44a0
>> 
>> Branch: refs/heads/master
>> Commit: 07cd44a06e4b16d38330d443fc771ada187d537f
>> Parents: dc9b6af
>> Author: rpopma <rp...@apache.org>
>> Authored: Sat Apr 16 21:40:29 2016 +0900
>> Committer: rpopma <rp...@apache.org>
>> Committed: Sat Apr 16 21:40:29 2016 +0900
>> 
>> ----------------------------------------------------------------------
>>  .../apache/logging/log4j/core/impl/MutableLogEvent.java  | 11 ++++++-----
>>  1 file changed, 6 insertions(+), 5 deletions(-)
>> ----------------------------------------------------------------------
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07cd44a0/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
>> ----------------------------------------------------------------------
>> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
>> index 5330c34..3dce409 100644
>> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
>> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
>> @@ -17,6 +17,7 @@ import java.util.Map;
>> 
>>  /**
>>   * Mutable implementation of the {@code LogEvent} interface.
>> + * @since 2.6
>>   */
>>  public class MutableLogEvent implements LogEvent, ReusableMessage {
>>      private static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
>> @@ -29,18 +30,18 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
>>      private Level level;
>>      private String loggerName;
>>      private Message message;
>> -    private Throwable thrown;
>>      private long timeMillis;
>> +    private Throwable thrown;
>> +    private ThrowableProxy thrownProxy;
>>      private Map<String, String> contextMap;
>>      private ThreadContext.ContextStack contextStack;
>>      private long threadId;
>>      private String threadName;
>>      private int threadPriority;
>> +    private StackTraceElement source;
>>      private boolean includeLocation;
>>      private boolean endOfBatch = false;
>>      private long nanoTime;
>> -    private ThrowableProxy thrownProxy;
>> -    private StackTraceElement source;
>>      private StringBuilder messageText;
>> 
>>      private static int size(final String property, final int defaultValue) {
>> @@ -87,7 +88,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
>>          source = null;
>>          contextMap = null;
>>          contextStack = null;
>> -        threadName = null;
>> +        // threadName = null; // THreadName should not be cleared
>>          // primitive fields that cannot be cleared:
>>          //timeMillis;
>>          //threadId;
>> @@ -143,7 +144,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
>> 
>>      public void setMessage(final Message msg) {
>>          if (msg instanceof ReusableMessage) {
>> -            ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
>> +            ((ReusableMessage) msg).formatTo(getMessageTextForWriting()); // init messageText
>>          } else {
>>              // if the Message instance is reused, there is no point in freezing its message here
>>              if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose

Fwd: [2/5] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name

Posted by Gary Gregory <ga...@gmail.com>.
1) I'm seeing some commits fly by sans unit tests. Are setting our selves
up for regressions?

2) Also, better comments would help (me). For example, this comments
states" THreadName should not be cleared" but why?

3) Typo in capitalization: THreadName

Gary
---------- Forwarded message ----------
From: <rp...@apache.org>
Date: Apr 16, 2016 5:55 AM
Subject: [2/5] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent
bugfix: don't clear thread name
To: <co...@logging.apache.org>
Cc:

LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/07cd44a0
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/07cd44a0
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/07cd44a0
>
> Branch: refs/heads/master
> Commit: 07cd44a06e4b16d38330d443fc771ada187d537f
> Parents: dc9b6af
> Author: rpopma <rp...@apache.org>
> Authored: Sat Apr 16 21:40:29 2016 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Sat Apr 16 21:40:29 2016 +0900
>
> ----------------------------------------------------------------------
>  .../apache/logging/log4j/core/impl/MutableLogEvent.java  | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07cd44a0/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
> ----------------------------------------------------------------------
> diff --git
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
> index 5330c34..3dce409 100644
> ---
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
> +++
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
> @@ -17,6 +17,7 @@ import java.util.Map;
>
>  /**
>   * Mutable implementation of the {@code LogEvent} interface.
> + * @since 2.6
>   */
>  public class MutableLogEvent implements LogEvent, ReusableMessage {
>      private static final int INITIAL_REUSABLE_MESSAGE_SIZE =
> size("log4j.initialReusableMsgSize", 128);
> @@ -29,18 +30,18 @@ public class MutableLogEvent implements LogEvent,
> ReusableMessage {
>      private Level level;
>      private String loggerName;
>      private Message message;
> -    private Throwable thrown;
>      private long timeMillis;
> +    private Throwable thrown;
> +    private ThrowableProxy thrownProxy;
>      private Map<String, String> contextMap;
>      private ThreadContext.ContextStack contextStack;
>      private long threadId;
>      private String threadName;
>      private int threadPriority;
> +    private StackTraceElement source;
>      private boolean includeLocation;
>      private boolean endOfBatch = false;
>      private long nanoTime;
> -    private ThrowableProxy thrownProxy;
> -    private StackTraceElement source;
>      private StringBuilder messageText;
>
>      private static int size(final String property, final int
> defaultValue) {
> @@ -87,7 +88,7 @@ public class MutableLogEvent implements LogEvent,
> ReusableMessage {
>          source = null;
>          contextMap = null;
>          contextStack = null;
> -        threadName = null;
> +        // threadName = null; // THreadName should not be cleared
>          // primitive fields that cannot be cleared:
>          //timeMillis;
>          //threadId;
> @@ -143,7 +144,7 @@ public class MutableLogEvent implements LogEvent,
> ReusableMessage {
>
>      public void setMessage(final Message msg) {
>          if (msg instanceof ReusableMessage) {
> -            ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
> +            ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
> // init messageText
>          } else {
>              // if the Message instance is reused, there is no point in
> freezing its message here
>              if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null)
> { // LOG4J2-898: user may choose
>
>

[2/5] logging-log4j2 git commit: LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name

Posted by rp...@apache.org.
LOG4J2-1334 MutableLogEvent bugfix: don't clear thread name


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

Branch: refs/heads/master
Commit: 07cd44a06e4b16d38330d443fc771ada187d537f
Parents: dc9b6af
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:40:29 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:40:29 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/impl/MutableLogEvent.java  | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/07cd44a0/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index 5330c34..3dce409 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -17,6 +17,7 @@ import java.util.Map;
 
 /**
  * Mutable implementation of the {@code LogEvent} interface.
+ * @since 2.6
  */
 public class MutableLogEvent implements LogEvent, ReusableMessage {
     private static final int INITIAL_REUSABLE_MESSAGE_SIZE = size("log4j.initialReusableMsgSize", 128);
@@ -29,18 +30,18 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
     private Level level;
     private String loggerName;
     private Message message;
-    private Throwable thrown;
     private long timeMillis;
+    private Throwable thrown;
+    private ThrowableProxy thrownProxy;
     private Map<String, String> contextMap;
     private ThreadContext.ContextStack contextStack;
     private long threadId;
     private String threadName;
     private int threadPriority;
+    private StackTraceElement source;
     private boolean includeLocation;
     private boolean endOfBatch = false;
     private long nanoTime;
-    private ThrowableProxy thrownProxy;
-    private StackTraceElement source;
     private StringBuilder messageText;
 
     private static int size(final String property, final int defaultValue) {
@@ -87,7 +88,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         source = null;
         contextMap = null;
         contextStack = null;
-        threadName = null;
+        // threadName = null; // THreadName should not be cleared
         // primitive fields that cannot be cleared:
         //timeMillis;
         //threadId;
@@ -143,7 +144,7 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
 
     public void setMessage(final Message msg) {
         if (msg instanceof ReusableMessage) {
-            ((ReusableMessage) msg).formatTo(getMessageTextForWriting());
+            ((ReusableMessage) msg).formatTo(getMessageTextForWriting()); // init messageText
         } else {
             // if the Message instance is reused, there is no point in freezing its message here
             if (!Constants.FORMAT_MESSAGES_IN_BACKGROUND && msg != null) { // LOG4J2-898: user may choose


Re: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

Posted by Gary Gregory <ga...@gmail.com>.
Ah! Thank you for the clarification.

Gary
On Apr 16, 2016 1:56 PM, "Remko Popma" <re...@gmail.com> wrote:

> Well, many existing unit tests fail without this. That's how I found there
> was a problem.
>
> Sent from my iPhone
>
> On 2016/04/16, at 23:28, Gary Gregory <ga...@gmail.com> wrote:
>
> Again: do we a matching unit test?
>
> Gary
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: Apr 16, 2016 5:55 AM
> Subject: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based
> layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to
> set up the same filters for MutableLogEvent but don't know how... This is a
> workaround.
> To: <co...@logging.apache.org>
> Cc:
>
> LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat()
> for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but
> don't know how... This is a workaround.
>
>
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit:
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cedf1552
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cedf1552
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cedf1552
>
> Branch: refs/heads/master
> Commit: cedf155230553d8c31bc669e3597b266dc3bf709
> Parents: 3f395f6
> Author: rpopma <rp...@apache.org>
> Authored: Sat Apr 16 21:49:44 2016 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Sat Apr 16 21:49:44 2016 +0900
>
> ----------------------------------------------------------------------
>  .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
>
>
>
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> ----------------------------------------------------------------------
> diff --git
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> index 7cbc798..22e2d36 100644
> ---
> a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> +++
> b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> @@ -22,6 +22,8 @@ import java.nio.charset.Charset;
>
>  import org.apache.logging.log4j.core.LogEvent;
>  import org.apache.logging.log4j.core.config.Configuration;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>  import org.apache.logging.log4j.core.util.StringBuilderWriter;
>  import org.apache.logging.log4j.util.Strings;
>
> @@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends
> AbstractStringLayout {
>
>      /**
>       * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
> -     *
> +     *
>       * @param event The LogEvent.
>       * @return The XML representation of the LogEvent.
>       */
>      @Override
>      public String toSerializable(final LogEvent event) {
> -        final StringBuilderWriter writer = new StringBuilderWriter();
> +        final StringBuilderWriter writer = new StringBuilderWriter();
>          try {
>              toSerializable(event, writer);
>              return writer.toString();
> @@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends
> AbstractStringLayout {
>          }
>      }
>
> +    private static LogEvent convertMutableToLog4jEvent(final LogEvent
> event) {
> +        // TODO Jackson-based layouts have certain filters set up for
> Log4jLogEvent.
> +        // TODO Need to set up the same filters for MutableLogEvent but
> don't know how...
> +        // This is a workaround.
> +        return event instanceof MutableLogEvent
> +                ?
> Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event,
> event.isIncludeLocation()))
> +                : event;
> +    }
> +
>      public void toSerializable(final LogEvent event, final Writer writer)
>              throws JsonGenerationException, JsonMappingException,
> IOException {
> -        objectWriter.writeValue(writer, event);
> +        objectWriter.writeValue(writer,
> convertMutableToLog4jEvent(event));
>          writer.write(eol);
>          markEvent();
>      }
>
>

Re: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

Posted by Remko Popma <re...@gmail.com>.
Well, many existing unit tests fail without this. That's how I found there was a problem. 

Sent from my iPhone

> On 2016/04/16, at 23:28, Gary Gregory <ga...@gmail.com> wrote:
> 
> Again: do we a matching unit test?
> 
> Gary
> 
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> Date: Apr 16, 2016 5:55 AM
> Subject: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.
> To: <co...@logging.apache.org>
> Cc: 
> 
> LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cedf1552
> Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cedf1552
> Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cedf1552
> 
> Branch: refs/heads/master
> Commit: cedf155230553d8c31bc669e3597b266dc3bf709
> Parents: 3f395f6
> Author: rpopma <rp...@apache.org>
> Authored: Sat Apr 16 21:49:44 2016 +0900
> Committer: rpopma <rp...@apache.org>
> Committed: Sat Apr 16 21:49:44 2016 +0900
> 
> ----------------------------------------------------------------------
>  .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> ----------------------------------------------------------------------
> diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> index 7cbc798..22e2d36 100644
> --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
> @@ -22,6 +22,8 @@ import java.nio.charset.Charset;
> 
>  import org.apache.logging.log4j.core.LogEvent;
>  import org.apache.logging.log4j.core.config.Configuration;
> +import org.apache.logging.log4j.core.impl.Log4jLogEvent;
> +import org.apache.logging.log4j.core.impl.MutableLogEvent;
>  import org.apache.logging.log4j.core.util.StringBuilderWriter;
>  import org.apache.logging.log4j.util.Strings;
> 
> @@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
> 
>      /**
>       * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
> -     *
> +     *
>       * @param event The LogEvent.
>       * @return The XML representation of the LogEvent.
>       */
>      @Override
>      public String toSerializable(final LogEvent event) {
> -        final StringBuilderWriter writer = new StringBuilderWriter();
> +        final StringBuilderWriter writer = new StringBuilderWriter();
>          try {
>              toSerializable(event, writer);
>              return writer.toString();
> @@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
>          }
>      }
> 
> +    private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
> +        // TODO Jackson-based layouts have certain filters set up for Log4jLogEvent.
> +        // TODO Need to set up the same filters for MutableLogEvent but don't know how...
> +        // This is a workaround.
> +        return event instanceof MutableLogEvent
> +                ? Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation()))
> +                : event;
> +    }
> +
>      public void toSerializable(final LogEvent event, final Writer writer)
>              throws JsonGenerationException, JsonMappingException, IOException {
> -        objectWriter.writeValue(writer, event);
> +        objectWriter.writeValue(writer, convertMutableToLog4jEvent(event));
>          writer.write(eol);
>          markEvent();
>      }
> 

Fwd: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

Posted by Gary Gregory <ga...@gmail.com>.
Again: do we a matching unit test?

Gary
---------- Forwarded message ----------
From: <rp...@apache.org>
Date: Apr 16, 2016 5:55 AM
Subject: [4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts
somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up
the same filters for MutableLogEvent but don't know how... This is a
workaround.
To: <co...@logging.apache.org>
Cc:

LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat()
for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but
don't know how... This is a workaround.


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

Branch: refs/heads/master
Commit: cedf155230553d8c31bc669e3597b266dc3bf709
Parents: 3f395f6
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:49:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:49:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index 7cbc798..22e2d36 100644
---
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -22,6 +22,8 @@ import java.nio.charset.Charset;

 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.util.StringBuilderWriter;
 import org.apache.logging.log4j.util.Strings;

@@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends
AbstractStringLayout {

     /**
      * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
-     *
+     *
      * @param event The LogEvent.
      * @return The XML representation of the LogEvent.
      */
     @Override
     public String toSerializable(final LogEvent event) {
-        final StringBuilderWriter writer = new StringBuilderWriter();
+        final StringBuilderWriter writer = new StringBuilderWriter();
         try {
             toSerializable(event, writer);
             return writer.toString();
@@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends
AbstractStringLayout {
         }
     }

+    private static LogEvent convertMutableToLog4jEvent(final LogEvent
event) {
+        // TODO Jackson-based layouts have certain filters set up for
Log4jLogEvent.
+        // TODO Need to set up the same filters for MutableLogEvent but
don't know how...
+        // This is a workaround.
+        return event instanceof MutableLogEvent
+                ? Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event,
event.isIncludeLocation()))
+                : event;
+    }
+
     public void toSerializable(final LogEvent event, final Writer writer)
             throws JsonGenerationException, JsonMappingException,
IOException {
-        objectWriter.writeValue(writer, event);
+        objectWriter.writeValue(writer, convertMutableToLog4jEvent(event));
         writer.write(eol);
         markEvent();
     }

[4/5] logging-log4j2 git commit: LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.

Posted by rp...@apache.org.
LOG4J2-1334 Jackson-based layouts somehow filter out Message.getFormat() for Log4jLogEvent. Need to set up the same filters for MutableLogEvent but don't know how... This is a workaround.


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

Branch: refs/heads/master
Commit: cedf155230553d8c31bc669e3597b266dc3bf709
Parents: 3f395f6
Author: rpopma <rp...@apache.org>
Authored: Sat Apr 16 21:49:44 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sat Apr 16 21:49:44 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/AbstractJacksonLayout.java   | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/cedf1552/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
index 7cbc798..22e2d36 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/AbstractJacksonLayout.java
@@ -22,6 +22,8 @@ import java.nio.charset.Charset;
 
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.core.impl.MutableLogEvent;
 import org.apache.logging.log4j.core.util.StringBuilderWriter;
 import org.apache.logging.log4j.util.Strings;
 
@@ -51,13 +53,13 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
 
     /**
      * Formats a {@link org.apache.logging.log4j.core.LogEvent}.
-     * 
+     *
      * @param event The LogEvent.
      * @return The XML representation of the LogEvent.
      */
     @Override
     public String toSerializable(final LogEvent event) {
-        final StringBuilderWriter writer = new StringBuilderWriter();        
+        final StringBuilderWriter writer = new StringBuilderWriter();
         try {
             toSerializable(event, writer);
             return writer.toString();
@@ -68,9 +70,18 @@ abstract class AbstractJacksonLayout extends AbstractStringLayout {
         }
     }
 
+    private static LogEvent convertMutableToLog4jEvent(final LogEvent event) {
+        // TODO Jackson-based layouts have certain filters set up for Log4jLogEvent.
+        // TODO Need to set up the same filters for MutableLogEvent but don't know how...
+        // This is a workaround.
+        return event instanceof MutableLogEvent
+                ? Log4jLogEvent.deserialize(Log4jLogEvent.serialize(event, event.isIncludeLocation()))
+                : event;
+    }
+
     public void toSerializable(final LogEvent event, final Writer writer)
             throws JsonGenerationException, JsonMappingException, IOException {
-        objectWriter.writeValue(writer, event);
+        objectWriter.writeValue(writer, convertMutableToLog4jEvent(event));
         writer.write(eol);
         markEvent();
     }