2

I am using logstash-logback-encoder:7.0.1

I am logging several structured arguments as follows

        log.info("Get container",
                v(StructuredLoggingFields.TENANT_ID, tenantId),
                v(StructuredLoggingFields.CONTAINER_ID, containerId));

NOTE: That class is instrumented with@Log4j2

but not seeing the arguments in the JSON in the log file

{
  "app":"Signal Service",
  "ts":"2022-02-02T18:22:21.312Z",
  "level":"INFO",
  "class":"com.tbd.platform.signal.controller.ContainerController",
  "method":"getContainer",
  "caller_file_name":"ContainerController.java",
  "line":153,"thread":"http-nio-8080-exec-2", 
  "msg":"Get container"
}

My logback-spring.xml is as follows

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <contextName>Signal Service</contextName>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <contextName>
                    <fieldName>app</fieldName>
                </contextName>
                <timestamp>
                    <fieldName>ts</fieldName>
                    <timeZone>UTC</timeZone>
                </timestamp>
                <logLevel>
                    <fieldName>level</fieldName>
                </logLevel>
                <callerData>
                    <classFieldName>class</classFieldName>
                    <methodFieldName>method</methodFieldName>
                    <lineFieldName>line</lineFieldName>
                </callerData>
                <threadName>
                    <fieldName>thread</fieldName>
                </threadName>
                <mdc/>
                <arguments>
                    <includeNonStructuredArguments>false</includeNonStructuredArguments>
                </arguments>
                <stackTrace>
                    <fieldName>stack</fieldName>
                </stackTrace>
                <message>
                    <fieldName>msg</fieldName>
                </message>
            </providers>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="CONSOLE"/>
    </root>
</configuration>

UPDATE: I seem to be able to see the proper outputs when using Spring 2.5.8 but not for Spring 2.5.9.

UPDATE 2: I seem to have tracked this down to log4j library update 2.17.1 since when I switch from @Log4j2 to @Slf4j I can see the fields

UPDATE 3: As this is increasingly looking like a bug (or at least something that should be documented) I logged as a GitHub issue here https://github.com/logfellow/logstash-logback-encoder/issues/754

kellyfj
  • 6,586
  • 12
  • 45
  • 66
  • The comments on your Github issue suggest you have solved this issue already - it was a misconfiguration really? Perhaps you could add an answer with the solution. – JohnXF Jul 10 '23 at 11:05

0 Answers0