Genadi Saltikov created LOG4J2-2459:
---------------------------------------

             Summary: JsonLayout seems not to produce classname, line and 
method 
                 Key: LOG4J2-2459
                 URL: https://issues.apache.org/jira/browse/LOG4J2-2459
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders, Layouts
    Affects Versions: 2.11.1
         Environment: Java 8
            Reporter: Genadi Saltikov


When we use a JsonLayout such as:
{noformat}
        <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>{noformat}
That only adds stuff like the message to the output JSON.

We tried various syntaxes to add \{{}}
{noformat}
%c{2}{noformat}
{{}}, {{}}
{noformat}
%M{noformat}
{\{ }}and \{{}}
{code:java}
%L{code}
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:
{noformat}
<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>{noformat}
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: 
{code:java}
StringMapMessage mapMsg = new StringMapMessage();
    mapMsg.put("method", "get the value somehow inside the custom logging 
method implementation");
    LOGGER.fatal(mapMsg);
{code}
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.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to