Best way to write custom json messages using log4j2
<p>I have been using log4j for different kind of projects and have some experience with log4j2. All implementations used the default appender and layout. Currently i need to write a application which writes in json format. So i tried the log4j2 JSONLayout layout by setting up a very simple log4j2 logger.</p>

<pre><code>public class JSONLogger {

    private static final Logger LOGGER = LogManager.getLogger();

    public static void main(String[] args) {
        JSONLogger jsonlogger = new JSONLogger() ;
    }

    public JSONLogger() {
        LOGGER.log(Level.FATAL, "hi mum!") ;

         int val1 = 10, val2 = 11, val3 = 12;

         LOGGER.log(Level.FATAL,"val1={}, val2={}, val3={}", val1, val2, val3);
    }

}
</code></pre>

<p>jsonLoggerProperties.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Configuration status="DEBUG"&gt;
    &lt;Properties&gt;
        &lt;Property name="log-path"&gt;/Users/petervannes/NetBeansProjects/JSONLogger/logfiles&lt;/Property&gt;
    &lt;/Properties&gt;

    &lt;Appenders&gt;
        &lt;RollingFile name="json_file_appender" fileName="${log-path}/jsonlogger.json"
                     filePattern="${log-path}/%d{yyyyMMdd}_jsonlogger-%i.json" &gt;
            &lt;JSONLayout complete="true" compact="false"/&gt;
            &lt;Policies&gt;
                &lt;SizeBasedTriggeringPolicy size="1 KB" /&gt;
            &lt;/Policies&gt;
            &lt;DefaultRolloverStrategy max="4"/&gt;
        &lt;/RollingFile&gt;

    &lt;/Appenders&gt;


    &lt;Loggers&gt;
        &lt;root level="debug" additivity="false"&gt;
            &lt;AppenderRef ref="json_file_appender"/&gt;
        &lt;/root&gt;
    &lt;/Loggers&gt;
&lt;/Configuration&gt;
</code></pre>

<p>Resulting in an log entry similar to;</p>

<pre><code>, {
  "timeMillis" : 1474573600359,
  "thread" : "main",
  "level" : "FATAL",
  "loggerName" : "JSONLogger",
  "message" : "val1=10, val2=11, val3=12",
  "contextStack" : [ "fieldName2" ],
  "endOfBatch" : false,
  "loggerFqcn" : "org.apache.logging.log4j.spi.AbstractLogger",
  "threadId" : 1,
  "threadPriority" : 5
}
</code></pre>

<p>What i need is to log to a JSON format like this;</p>

<pre><code>, {
  "DateTime" : "08/01/2016 21:33:22.334",
  "level" : "FATAL",
  "Summary" : "Something has gone wrong",
  "ChainManager" : "Manager A",
  "Optionals" : { "Key_1": "Value1",
                  "Key_2": "Value2" }
}
</code></pre>

<p>Is this possibile with the log4j2 JSONLayout or is there any other layout i can use to get this format ? </p>