You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Atle Tokle (JIRA)" <ji...@apache.org> on 2018/02/14 09:07:00 UTC

[jira] [Created] (LOG4J2-2248) Using MapMessage and JsonLayout should create json for the Map key/values

Atle Tokle created LOG4J2-2248:
----------------------------------

             Summary: Using MapMessage and JsonLayout should create json for the Map key/values
                 Key: LOG4J2-2248
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2248
             Project: Log4j 2
          Issue Type: Improvement
          Components: Layouts
    Affects Versions: 2.10.0
            Reporter: Atle Tokle


I want to add extra parameters to structured Json output, and can do that by using ThreadContext, like shown in code below.
{code:java}
ThreadContext.put("key1", value1);
ThreadContext.put("key2", value2);
timerLogger.info("Values");
ThreadContext.remove("key1");
ThreadContext.remove("key2");
{code}
This is very intrusive in the code, and I tried to use MapMessage instead like this:
{code:java}
this. logger.info(new MapMessage().with("key1", "value1").with("key2", "value2"));{code}
I see that the MapMessage can format messages as key="value", json, java and XML. I use a JsonAppender to ouput a format that is easy indexable by our log-management system. But the MapMessage is not output as json. I get this:
{code:java}
"message" : "key1=\"value1\" key2=\"value2\"", {code}
But I want:
{code:java}
"message" : {"key1" : "value1", "key2" : "value2" }{code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)