title: Output Spark application id in the logs with Log4j
body: <p>I have a custom Log4j file for the Spark application. I would like to output Spark app id along with other attributes like message and date so the JSON string structure would look like this:</p>
  
  <pre><code>{"name":,"time":,"date":,"level":,"thread":,"message":,"app_id":}
  </code></pre>
  
  <p>Now, this structure looks like this:</p>
  
  <pre><code>{"name":,"time":,"date":,"level":,"thread":,"message":}
  </code></pre>
  
  <p>How can I define such layout for the Spark driver logs?</p>
  
  <p>My log4j file looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"&gt;
  &lt;log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'&gt;
  
      &lt;appender name="Json" class="org.apache.log4j.ConsoleAppender"&gt;
          &lt;layout class="org.apache.hadoop.log.Log4Json"&gt;
              &lt;param name="ConversionLayout" value=""/&gt;
          &lt;/layout&gt;
      &lt;/appender&gt;
  
      &lt;root&gt;
          &lt;level value="INFO"/&gt;
          &lt;appender-ref ref="Json"/&gt;
      &lt;/root&gt;
  &lt;/log4j:configuration&gt;
  </code></pre>