Ah! Thank you for the clarification. Gary On Apr 16, 2016 1:56 PM, "Remko Popma" <[email protected]> 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 <[email protected]> wrote: > > Again: do we a matching unit test? > > Gary > ---------- Forwarded message ---------- > From: <[email protected]> > 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: <[email protected]> > 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 <[email protected]> > Authored: Sat Apr 16 21:49:44 2016 +0900 > Committer: rpopma <[email protected]> > 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(); > } > >
