I have the following test. I add something to the context map and the context stack, and then write a message. The message goes into graylog, but there is nothing about the pushed message or the pushed key.
@Test
public void test2() {
try (CloseableThreadContext.Instance c = CloseableThreadContext.push("pushed message").put("pushed key", "pushed value")){
LogManager.getLogger().warn("warn level message seeing if it goes into graylog.");
}
}
I used both of these configurations, and neither one worked.
Attempt 1:
<Gelf name="gelf" host="udp:localhost" port="12201" version="1.1" extractStackTrace="true"
filterStackTrace="true" mdcProfiling="true" includeFullMdc="true" maximumMessageSize="8192"
originHost="%host{fqdn}">
<Field name="class" pattern="%c"/>
<Field name="classname" pattern="%c{1}"/>
<Field name="exception" pattern="%ex{full}"/>
<Field name="method" pattern="%method"/>
<Field name="line" pattern="%line"/>
<Field name="application_name" pattern="${application}"/>
<Field name="sequenceNumber" pattern="%sequenceNumber"/>
<Field name="application_version" pattern="${application.version}"/>
<Field name="marker" pattern="%marker"/>
<Field name="thread" pattern="%thread"/>
<Field name="system_nano_time" pattern="%nano"/>
<Field name="app_uptime" pattern="%relative"/>
<Field name="severity" pattern="%level{WARN=Warning, DEBUG=Debug, ERROR=Error, TRACE=Trace, INFO=Info}"/>
</Gelf>
Attempt 2:
<Gelf name="gelf" host="udp:localhost" port="12201" version="1.1" extractStackTrace="true"
filterStackTrace="true" mdcProfiling="true" includeFullMdc="true" maximumMessageSize="8192"
originHost="%host{fqdn}">
<Field name="timestamp" pattern="%d{dd MMM yyyy HH:mm:ss,SSS}" />
<Field name="level" pattern="%level" />
<Field name="simpleClassName" pattern="%C{1}" />
<Field name="className" pattern="%C" />
<Field name="server" pattern="%host" />
<Field name="server.fqdn" pattern="%host{fqdn}" />
<DynamicMdcFields regex="mdc.*" />
<Field name="mdcField2" mdc="mdcField2" />
<DynamicMdcFields regex="(mdc|MDC)fields" />
<DynamicMdcFieldType regex="my_field.*" type="String" />
</Gelf>
I looked here How to transfer MDC via gelf to graylog? and that didn't work - the messages showed up in graylog without the MDC.
I am using the following dependency:
<dependency>
<groupId>biz.paluch.logging</groupId>
<artifactId>logstash-gelf</artifactId>
<version>1.15.0</version>
</dependency>