Description
When we use a JsonLayout such as:
<Kafka name="KafkaAppender" topic="topic1"> <JsonLayout compact="true"> <KeyValuePair key="service" value="some_app_tag"/> <KeyValuePair key="@timestamp" value="${date:yyyy-MM-dd HH:mm:ss.SSS}"/> <KeyValuePair key="host_name" value="${hostName}"/> <KeyValuePair key="unique_id" value="$${map:name:-NA}"/> </JsonLayout> <Property name="bootstrap.servers">kafka1.com:9092,kafka2.com:9092,kafka3.com:9092</Property> </Kafka>
That only adds stuff like the message to the output JSON.
We tried various syntaxes to add {{}}
%c{2}
}}, {{
%M
{{ }}and {{}}
%L
In various syntax variations, but they all just output the literals and are not being substituted.
The above placeholders do work in a Console Appender for example:
<Console name="ConsoleAppender" target="SYSTEM_OUT" follow="true"> <PatternLayout> <!-- {Timestamp} {Log Level} [{Thread Name}] [Execution/Error Id] {Class}.{Method}({FileName}:{Line}): {Message} /newline\ {Throwable/Exception} --> <pattern>%23.23d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] [$${map:name:-NA}] %c{1}.%M(%F:%L): %highlight{%m%n%throwable}</pattern> </PatternLayout> </Console>
We are thinking it has to be a bug or something, if we get no other indication we are going to try and work around this by re-implmenting the various log method signatures (error, fatal, debug etc) and using something along the lines of:
StringMapMessage mapMsg = new StringMapMessage(); mapMsg.put("method", "get the value somehow inside the custom logging method implementation"); LOGGER.fatal(mapMsg);
Does that make sense?
This is the doc link we've been following, which seems not precise enough:
https://logging.apache.org/log4j/2.x/manual/layouts.html#JSONLayout
line, method etc are obviously outputted for an exception log with stack trace, but not for a regular log message which does not contain some Exception based object.