Alla Gofman created LOG4J2-2873:
-----------------------------------

             Summary: Failed to parse json string to LogEvent when massage type 
is MapMessage
                 Key: LOG4J2-2873
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2873
             Project: Log4j 2
          Issue Type: Bug
            Reporter: Alla Gofman


I create LogEvent where message is of MapMessage type (key-value pairs).

I send this log even to SocketAppender by JsonLayout. (I tried 2 options with 
setObjectMessageAsJsonObject true and false)

The Json created:
{quote}{"instant":\{"epochSecond":1592427900,"nanoOfSecond":8396100},"thread":"MetricsScheduler-7","level":"alert","loggerName":"AlertsLogger","message":"\{key1=value1,
 component=mft-server, id=DRAFT_101, alertmsg=MFT Server isn't 
responding!}","endOfBatch":false,"loggerFqcn":"com.*.*.saas.alerts.AlertsLoggerWrapper","contextMap":{},"threadId":26,"threadPriority":5}
{quote}
On ServerSocket side I want to parse/deserialize this json string to  LogEvent 
and log it to File Appender:
{quote}{{PatternLayout. JSONObject jobj = new JSONObject(line);}}
{{LogEvent logEvent = new JsonLogEventParser().parseFrom(line);}}{quote}
 

Then parseFrom() build the LogEvent, message object create of type 
SimpleMessage and not MapMessage. Then it comes to resolving %map pattern in 
MapPatternConverter.format() - do nothing and return.
{quote}public void format(final LogEvent event, final StringBuilder toAppendTo) 
{
 MapMessage msg;
 if (event.getMessage() instanceof MapMessage) {
 msg = (MapMessage) event.getMessage();
 } else {
 return;
 }{quote}
 

 

 

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to