Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2248

Using MapMessage and JsonLayout should create json for the Map key/values

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.10.0
    • None
    • Layouts
    • None

    Description

      I want to add extra parameters to structured Json output, and can do that by using ThreadContext, like shown in code below.

      ThreadContext.put("key1", value1);
      ThreadContext.put("key2", value2);
      timerLogger.info("Values");
      ThreadContext.remove("key1");
      ThreadContext.remove("key2");
      

      This is very intrusive in the code, and I tried to use MapMessage instead like this:

      this. logger.info(new MapMessage().with("key1", "value1").with("key2", "value2"));

      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:

      "message" : "key1=\"value1\" key2=\"value2\"", 

      But I want:

      "message" : {"key1" : "value1", "key2" : "value2" }

      Attachments

        Activity

          People

            Unassigned Unassigned
            atokle Atle Tokle
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: