Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1555

Logback-access %B is not 0 when HTTP status code is 204 No Content

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.2.3
    • logback-access
    • None
    • Java 11, Gradle 6.8.3

    Description

      https://tomcat.apache.org/tomcat-8.0-doc/config/valve.html says

      %b - Bytes sent, excluding HTTP headers, or '-' if zero
      %B - Bytes sent, excluding HTTP headers
      

      That is, %B returns number 0, instead of '-' if content-length is 0. We expected the same behavior from logback-access. However, this does not seem to be the case.

      I created a simple Spring Boot project with only "spring-boot-starter-web" and "logback-access:1.2.3", with simple configuration for logback-access.xml. Related to the ticket LOGBACK-1554, I knew %b and %B works only for String object. I created 4 simple REST APIs, all returning String object, but with non-empty string, empty string, null string, and null string with HTTP 204 status code.

      http://localhost:8080/string
      http://localhost:8080/empty
      http://localhost:8080/null
      http://localhost:8080/noContent
      

      I configured the app to use both Tomcat Access log and Logback-access log, the corresponding results are

      Spring Boot Tomcat Access Log

      0:0:0:0:0:0:0:1 - - [30/Mar/2021:11:27:13 -0500] "GET /string HTTP/1.1" 200 6 6 8
      0:0:0:0:0:0:0:1 - - [30/Mar/2021:11:27:15 -0500] "GET /empty HTTP/1.1" 200 - 0 1
      0:0:0:0:0:0:0:1 - - [30/Mar/2021:11:27:16 -0500] "GET /null HTTP/1.1" 200 - 0 2
      0:0:0:0:0:0:0:1 - - [30/Mar/2021:11:27:19 -0500] "GET /noContent HTTP/1.1" 204 - 0 1
      

      Logback-access Log

      Logback-access 0:0:0:0:0:0:0:1 - - 30/Mar/2021:11:27:13 -0500 "GET /string HTTP/1.1" 200 6 6 8
      Logback-access 0:0:0:0:0:0:0:1 - - 30/Mar/2021:11:27:15 -0500 "GET /empty HTTP/1.1" 200 0 0 1
      Logback-access 0:0:0:0:0:0:0:1 - - 30/Mar/2021:11:27:16 -0500 "GET /null HTTP/1.1" 200 0 0 2
      Logback-access 0:0:0:0:0:0:0:1 - - 30/Mar/2021:11:27:19 -0500 "GET /noContent HTTP/1.1" 204 - - 1
      

      You can see %B in Tomcat access log is 0 when HTTP status is 204. However, it is '-' in logback-access log.

      I attached my simple project for you to reproduce it. You can unzip it, and run "gradlew clean bootRun". Please let me know if any additional information is needed. Thanks.

      Attachments

        Activity

          People

            logback-dev Logback dev list
            dlu-lv Dongfeng Lu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: