[ 
https://issues.apache.org/jira/browse/LOG4J2-3298?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Pavlovich updated LOG4J2-3298:
-----------------------------------
    Description: 
Currently, if a user's object is able to generate well-formed JSON string, it 
will be escaped. It would be great if there was a way to config the 
JsonTemplateLayout to _not escape_ certain payloads. This allows the json to be 
fully formed and contain model object data that can be parsed out later without 
any un-formatting. 

Example log entry:
{noformat}
{"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":"{ 
\"Order\" { \"id\": \"3977\", \"customerName\": \"Customer-8625\", 
\"createdDate\": \"2022-01-07T09:51:01.056580-06:00\"} 
}","process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
{noformat}

Desired output:
{noformat}
{"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":{ "Order" 
{ "id": "3977", "customerName": "Customer-8625", "createdDate": 
"2022-01-07T09:51:01.056580-06:00"} 
},"process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
{noformat}

Proposed requirements:
1. Users would have to pre-escape their JSON string in order to not break 
overall log json format

Implementation approach options:
1. Update JSONTemplate configuration to allow a rawJSON, similar to 
'stringified' 
2. Data is written down as a JSON object "message": { }
3. User should invoke using an ObjectMessage: logger.info(new 
ObjectMessage(objectInstance)

{noformat}
"message": {
    "$resolver": "message",
    "rawJSON": true
  },
{noformat}


  was:
Currently, if a user's object is able to generate well-formed JSON string, it 
will be escaped. It would be great if there was a way to config the 
JsonTemplateLayout to _not escape_ certain payloads. This allows the json to be 
fully formed and contain model object data that can be parsed out later without 
any un-formatting. 

Example log entry:
{noformat}
{"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":"{ 
\"Order\" { \"id\": \"3977\", \"customerName\": \"Customer-8625\", 
\"createdDate\": \"2022-01-07T09:51:01.056580-06:00\"} 
}","process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
{noformat}

Desired output:
{noformat}
{"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":{ "Order" 
{ "id": "3977", "customerName": "Customer-8625", "createdDate": 
"2022-01-07T09:51:01.056580-06:00"} 
},"process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
{noformat}

Proposed requirements:
1. Users would have to pre-escape their JSON string in order to not break 
overall log json format

Implementation approach options:
1. Update JSONTemplate configuration to allow a rawJSON, similar to 
'stringified' 
2. Data is written down as a JSON object "message": { }

{noformat}
"message": {
    "$resolver": "message",
    "rawJSON": true
  },
{noformat}



> Update JSONTemplateFormat to support not escaping certain payloads
> ------------------------------------------------------------------
>
>                 Key: LOG4J2-3298
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3298
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: JsonTemplateLayout
>            Reporter: Matt Pavlovich
>            Assignee: Volkan Yazici
>            Priority: Minor
>
> Currently, if a user's object is able to generate well-formed JSON string, it 
> will be escaped. It would be great if there was a way to config the 
> JsonTemplateLayout to _not escape_ certain payloads. This allows the json to 
> be fully formed and contain model object data that can be parsed out later 
> without any un-formatting. 
> Example log entry:
> {noformat}
> {"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":"{ 
> \"Order\" { \"id\": \"3977\", \"customerName\": \"Customer-8625\", 
> \"createdDate\": \"2022-01-07T09:51:01.056580-06:00\"} 
> }","process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
> {noformat}
> Desired output:
> {noformat}
> {"@timestamp":"2022-01-07T19:14:01.060Z","log.level":"INFO","message":{ 
> "Order" { "id": "3977", "customerName": "Customer-8625", "createdDate": 
> "2022-01-07T09:51:01.056580-06:00"} 
> },"process.thread.name":"main","log.logger":"io.hyte.dev.log.ProcessService"}
> {noformat}
> Proposed requirements:
> 1. Users would have to pre-escape their JSON string in order to not break 
> overall log json format
> Implementation approach options:
> 1. Update JSONTemplate configuration to allow a rawJSON, similar to 
> 'stringified' 
> 2. Data is written down as a JSON object "message": { }
> 3. User should invoke using an ObjectMessage: logger.info(new 
> ObjectMessage(objectInstance)
> {noformat}
> "message": {
>     "$resolver": "message",
>     "rawJSON": true
>   },
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to