<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to add additional fields to log4j-submitted JSON? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-additional-fields-to-log4j-submitted-JSON/m-p/479660#M82283</link>
    <description>&lt;P&gt;Ok, there are &lt;EM&gt;two&lt;/EM&gt; options here, which can also be combined:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Set the &lt;CODE&gt;includeMDC&lt;/CODE&gt; parameter to &lt;CODE&gt;true&lt;/CODE&gt; and hope (or provide for), the MDC in your case contains all of the fields you need — they will be in the &lt;CODE&gt;properties&lt;/CODE&gt; sub-dictionary of every logged event.&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Set the &lt;CODE&gt;messageFormat&lt;/CODE&gt; parameter to &lt;CODE&gt;json&lt;/CODE&gt; -- and format your message to be in proper JSON itself:&lt;/P&gt;

&lt;P&gt;&lt;LAYOUT class="org.apache.log4j.EnhancedPatternLayout"&gt;&lt;BR /&gt;
    &lt;OBJECT&gt;&lt;PARAM name="ConversionPattern" /&gt;&lt;BR /&gt;
        value="{"cat": "meow", "message": "%m"}"/&amp;gt;&lt;BR /&gt;
&lt;/OBJECT&gt;&lt;/LAYOUT&gt;&lt;BR /&gt;
The &lt;CODE&gt;message&lt;/CODE&gt; field of the submitted event will then itself be a dictionary. In the above example, that sub-dictionary will contain two fields: &lt;CODE&gt;cat&lt;/CODE&gt; and &lt;CODE&gt;message&lt;/CODE&gt;. These can be searched for on Splunk-server as &lt;CODE&gt;message.cat="meow"&lt;/CODE&gt;.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I'd still like to be able to add additional fields &lt;EM&gt;next to&lt;/EM&gt; the &lt;CODE&gt;message&lt;/CODE&gt; and the &lt;CODE&gt;severity&lt;/CODE&gt;, though -- not inside a sub-dictionary...&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jan 2020 20:45:53 GMT</pubDate>
    <dc:creator>unitedmarsupial</dc:creator>
    <dc:date>2020-01-06T20:45:53Z</dc:date>
    <item>
      <title>How to add additional fields to log4j-submitted JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-additional-fields-to-log4j-submitted-JSON/m-p/479659#M82282</link>
      <description>&lt;P&gt;We're using Splunk's "javalogging" JAR to send events to Splunk from our Java-application directly. This works, but the event's JSON received by the server has only two fields: &lt;CODE&gt;message&lt;/CODE&gt; and &lt;CODE&gt;severity&lt;/CODE&gt; (plus the &lt;CODE&gt;host&lt;/CODE&gt;, &lt;CODE&gt;index&lt;/CODE&gt;, &lt;CODE&gt;source&lt;/CODE&gt;, and &lt;CODE&gt;sourcetype&lt;/CODE&gt; of course):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{   
    "event": {
      "message": "This is a test 20:41:34",
      "severity": "ERROR"
    },
    "host" = "myhost",
    "source" = "mysource",
    "sourcetype" = "logj4"
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We'd like to add some others -- to help us identify the application and the application instance, et cætera. Can this be done via configuration file -- without recompiling the code?&lt;/P&gt;

&lt;P&gt;I realize, we can use a pattern-layout to prepend the additional data to the message:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;param name="ConversionPattern" value="FIELD1=VALUE1 FIELD2=VALUE2 %m"/&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but then the extra fields would simply be part of the &lt;CODE&gt;message&lt;/CODE&gt; -- not separately-indexed fields of their own...&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 16:40:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-additional-fields-to-log4j-submitted-JSON/m-p/479659#M82282</guid>
      <dc:creator>unitedmarsupial</dc:creator>
      <dc:date>2020-01-06T16:40:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to add additional fields to log4j-submitted JSON?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-add-additional-fields-to-log4j-submitted-JSON/m-p/479660#M82283</link>
      <description>&lt;P&gt;Ok, there are &lt;EM&gt;two&lt;/EM&gt; options here, which can also be combined:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Set the &lt;CODE&gt;includeMDC&lt;/CODE&gt; parameter to &lt;CODE&gt;true&lt;/CODE&gt; and hope (or provide for), the MDC in your case contains all of the fields you need — they will be in the &lt;CODE&gt;properties&lt;/CODE&gt; sub-dictionary of every logged event.&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Set the &lt;CODE&gt;messageFormat&lt;/CODE&gt; parameter to &lt;CODE&gt;json&lt;/CODE&gt; -- and format your message to be in proper JSON itself:&lt;/P&gt;

&lt;P&gt;&lt;LAYOUT class="org.apache.log4j.EnhancedPatternLayout"&gt;&lt;BR /&gt;
    &lt;OBJECT&gt;&lt;PARAM name="ConversionPattern" /&gt;&lt;BR /&gt;
        value="{"cat": "meow", "message": "%m"}"/&amp;gt;&lt;BR /&gt;
&lt;/OBJECT&gt;&lt;/LAYOUT&gt;&lt;BR /&gt;
The &lt;CODE&gt;message&lt;/CODE&gt; field of the submitted event will then itself be a dictionary. In the above example, that sub-dictionary will contain two fields: &lt;CODE&gt;cat&lt;/CODE&gt; and &lt;CODE&gt;message&lt;/CODE&gt;. These can be searched for on Splunk-server as &lt;CODE&gt;message.cat="meow"&lt;/CODE&gt;.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I'd still like to be able to add additional fields &lt;EM&gt;next to&lt;/EM&gt; the &lt;CODE&gt;message&lt;/CODE&gt; and the &lt;CODE&gt;severity&lt;/CODE&gt;, though -- not inside a sub-dictionary...&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 20:45:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-add-additional-fields-to-log4j-submitted-JSON/m-p/479660#M82283</guid>
      <dc:creator>unitedmarsupial</dc:creator>
      <dc:date>2020-01-06T20:45:53Z</dc:date>
    </item>
  </channel>
</rss>

