logstash-logback-encoder

How to filter headers of request and response in AccessEventCompositeJsonEncoder


The documentation specifies to use filter in responseHeaders. But what field to use to say to exclude or include a header.

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="net.logstash.logback.encoder.AccessEventCompositeJsonEncoder">
      <providers>
        <responseHeaders>
          <fieldName>resp_header</fieldName>
          <filter>
            <include>Pragma</include>
          </filter>
        </responseHeaders>
    </encoder>
  </appender>

  <appender-ref ref="STDOUT" />
</configuration>

The following configuration logs full response headers. How to log only the specified headers ?

please refer responseHeaders in documentation

Update:

The following config is also not working

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="net.logstash.logback.encoder.AccessEventCompositeJsonEncoder">
      <providers>
        <responseHeaders>
          <fieldName>resp_header</fieldName>
          <filter>
            <requestHeaderFilter>
              <include>Content-Type</include>
            </requestHeaderFilter>
          </filter>
        </responseHeaders>
    </encoder>
  </appender>
  <appender-ref ref="STDOUT" />
</configuration>

Answer:

Check your version. The 1st code block works with version 6.6


Solution

  • The version(4.4) was older, so it was not supported. Upgraded the version to 6.6