[
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 JSON string is pushed to ThreadContext, 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}
{
"instant": {
"epochSecond": 1640632561,
"nanoOfSecond": 287515000
},
"thread": "main",
"level": "INFO",
"loggerName": "io.hyte.dev.c.ServiceC",
"message": "Doing way other thing with order: 3235",
"contextStack": ["{ \"Task\" {\
"id\"=\"3623\", \"orderId\"=\"1345\", \"taskStatus\"=\"null\",
\"startDateTime\"=\"2021-12-27T06:07:01.363232-06:00\",
\"endDateTime\"=\"2021-12-27T17:10:01.365430-06:00\"} }",
"{ \"Order\" { \"id\"=\"3235\", \"customerName\"=\"Customer-8780\",
\"createdDate\"=\"2021-12-27T08:55:01.366162-06:00\"} }"],
"endOfBatch": false,
"loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
"threadId": 1,
"threadPriority": 5
}
{noformat}
Desired output:
{noformat}
{
"instant": {
"epochSecond": 1640632561,
"nanoOfSecond": 287515000
},
"thread": "main",
"level": "INFO",
"loggerName": "io.hyte.dev.c.ServiceC",
"message": "Doing way other thing with order: 3235",
"contextStack": [{ "Task" { "id"="3623", "orderId"="1345", "taskStatus"=null,
"startDateTime"="2021-12-27T06:07:01.363232-06:00",
"endDateTime"="2021-12-27T17:10:01.365430-06:00"} }",
{ "Order" { "id"="3235", "customerName"="Customer-8780",
"createdDate"="2021-12-27T08:55:01.366162-06:00"} }],
"endOfBatch": false,
"loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
"threadId": 1,
"threadPriority": 5
}
{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. Prefix " { n o e s c } " or other marker macro to instruct JSONWriter skip
escaping for that string
{noformat}
ThreadContext.push("{noesc}" + JSONString(myModelObject));
{noformat}
was:
Currently, if a JSON string is pushed to ThreadContext, 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}
{
"instant": {
"epochSecond": 1640632561,
"nanoOfSecond": 287515000
},
"thread": "main",
"level": "INFO",
"loggerName": "io.hyte.dev.c.ServiceC",
"message": "Doing way other thing with order: 3235",
"contextStack": ["{ \"Task\" {\
"id\"=\"3623\", \"orderId\"=\"1345\", \"taskStatus\"=\"null\",
\"startDateTime\"=\"2021-12-27T06:07:01.363232-06:00\",
\"endDateTime\"=\"2021-12-27T17:10:01.365430-06:00\"} }",
"{ \"Order\" { \"id\"=\"3235\", \"customerName\"=\"Customer-8780\",
\"createdDate\"=\"2021-12-27T08:55:01.366162-06:00\"} }"],
"endOfBatch": false,
"loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
"threadId": 1,
"threadPriority": 5
}
{noformat}
Desired output:
{noformat}
{
"instant": {
"epochSecond": 1640632561,
"nanoOfSecond": 287515000
},
"thread": "main",
"level": "INFO",
"loggerName": "io.hyte.dev.c.ServiceC",
"message": "Doing way other thing with order: 3235",
"contextStack": [{ "Task" { "id"="3623", "orderId"="1345", "taskStatus"=null,
"startDateTime"="2021-12-27T06:07:01.363232-06:00",
"endDateTime"="2021-12-27T17:10:01.365430-06:00"} }",
{ "Order" { "id"="3235", "customerName"="Customer-8780",
"createdDate"="2021-12-27T08:55:01.366162-06:00"} }],
"endOfBatch": false,
"loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
"threadId": 1,
"threadPriority": 5
}
{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. Prefix ' { n o e s c } ' or other marker macro to instruct JSONWriter skip
escaping for that string
{noformat}
ThreadContext.push("{noesc}" + JSONString(myModelObject));
{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
> Priority: Minor
>
> Currently, if a JSON string is pushed to ThreadContext, 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}
> {
> "instant": {
> "epochSecond": 1640632561,
> "nanoOfSecond": 287515000
> },
> "thread": "main",
> "level": "INFO",
> "loggerName": "io.hyte.dev.c.ServiceC",
> "message": "Doing way other thing with order: 3235",
> "contextStack": ["{ \"Task\" {\
> "id\"=\"3623\", \"orderId\"=\"1345\", \"taskStatus\"=\"null\",
> \"startDateTime\"=\"2021-12-27T06:07:01.363232-06:00\",
> \"endDateTime\"=\"2021-12-27T17:10:01.365430-06:00\"} }",
> "{ \"Order\" { \"id\"=\"3235\", \"customerName\"=\"Customer-8780\",
> \"createdDate\"=\"2021-12-27T08:55:01.366162-06:00\"} }"],
>
> "endOfBatch": false,
> "loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
> "threadId": 1,
> "threadPriority": 5
> }
> {noformat}
> Desired output:
> {noformat}
> {
> "instant": {
> "epochSecond": 1640632561,
> "nanoOfSecond": 287515000
> },
> "thread": "main",
> "level": "INFO",
> "loggerName": "io.hyte.dev.c.ServiceC",
> "message": "Doing way other thing with order: 3235",
> "contextStack": [{ "Task" { "id"="3623", "orderId"="1345",
> "taskStatus"=null, "startDateTime"="2021-12-27T06:07:01.363232-06:00",
> "endDateTime"="2021-12-27T17:10:01.365430-06:00"} }",
> { "Order" { "id"="3235", "customerName"="Customer-8780",
> "createdDate"="2021-12-27T08:55:01.366162-06:00"} }],
> "endOfBatch": false,
> "loggerFqcn": "org.apache.logging.log4j.spi.AbstractLogger",
> "threadId": 1,
> "threadPriority": 5
> }
> {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. Prefix " { n o e s c } " or other marker macro to instruct JSONWriter skip
> escaping for that string
> {noformat}
> ThreadContext.push("{noesc}" + JSONString(myModelObject));
> {noformat}
>
--
This message was sent by Atlassian Jira
(v8.20.1#820001)