SAP / cf-java-logging-support

The Java Logging Support for Cloud Foundry supports the creation of structured log messages and the collection of request metrics
Apache License 2.0
76 stars 46 forks source link

Log4j2 JsonPatternLayout might generate invalid JSON in v3.5.3 #124

Closed KarstenSchnitter closed 2 years ago

KarstenSchnitter commented 2 years ago

With v3.5.3 come a new feature, that fields with default value are by default not emitted in the generated log messages. For the cf-java-logging-support-log4j2, this can result in invalid JSON messages. The feature can be disabled with the XML attribute sendDefaultValues="true.

<Configuration
   status="warn" strict="true"
   packages="com.sap.hcp.cf.log4j2.converter,com.sap.hcp.cf.log4j2.layout">
    <Appenders>
        <Console name="STDOUT-JSON" target="SYSTEM_OUT" follow="true">
            <JsonPatternLayout charset="utf-8" sendDefaultValues="true" />
        </Console>
        <Console name="STDOUT" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} [%mdc] - %msg%n"/>
        </Console>
    </Appenders>
  <Loggers>
     <Root level="${LOG_ROOT_LEVEL:-WARN}">
        <!-- Use 'STDOUT' instead for human-readable output -->
        <AppenderRef ref="STDOUT-JSON" />
     </Root>
     <!-- request metrics are reported using INFO level, so make sure the instrumentation loggers are set to that level -->
     <Logger name="com.sap.hcp.cf" level="INFO"/>
  </Loggers>
</Configuration>
KarstenSchnitter commented 2 years ago

the proposed mitigation is ineffective. I will provide a fix ASAP.