Reputation: 335
I'm trying to include a calling method name as a separate field in the Gelf:
<Socket name="Graylog" protocol="udp" host="127.0.0.1" port="12201">
<GelfLayout>
<KeyValuePair key="method" value="%M"/>
</GelfLayout>
</Socket>
But in the Graylog this field's value appears just as %M
, no value substitution is happening.
I read the manual, but couldn't find anything about resolving message pattern placeholders in the custom fields.
I know that logstash-gelf can do this, but is it possible to do this without using an extra plugin, using the standard log4j2?
Upvotes: 2
Views: 368
Reputation: 1305
I wanted to show what ID the thread had, but just as you, I noticed that the text was treated as static text. I looked into this and acording to the documentation it should be possible to use patterns, but not in <KeyValuePair>
<GelfLayout includeThreadContext="true" threadContextIncludes="loginId,requestId">
%d %5p [%t] %c{1} %X{loginId, requestId} - %m%n
<KeyValuePair key="additionalField1" value="constant value"/>
<KeyValuePair key="additionalField2" value="$${ctx:key}"/>
</GelfLayout>
Look at the second row, above. It looks as if it would be possible to use pattern placeholders as a general message. I have, however, not been able to get this to work, maybe the version I use is to old.
I have found out that Log4j2 does not currently support what we want. But it will do in the next version (2.15.0). I have no idea, how ever, when the next version will be released, se issue LOG4J2-3041 for details.
References:
Upvotes: 1