Details
-
Bug
-
Resolution: Unresolved
-
Major
-
None
-
1.2.3
-
None
-
Java 11, Gradle
Description
Originally, we were trying to get Tomcat access log in JSON format. We followed the example in https://github.com/jochenchrist/spring-boot-access-logs-demo and everything seems to work well, except that we were not able to get response's content length.
To narrow things down, I created a simple Spring Boot project with only "spring-boot-starter-web" and "logback-access:1.2.3" (No logstash here), with simple configuration for logback-access.xml. I created 4 simple REST APIs, started the app and ran the following 4 requests in browser.
http://localhost:8080/list http://localhost:8080/map http://localhost:8080/long http://localhost:8080/string
The browser displays the response correctly in JSON format. And in the console, the corresponding access log entries were
0:0:0:0:0:0:0:1 - - 26/Mar/2021:11:04:34 -0500 "GET /list HTTP/1.1" 200 124 - - - 0:0:0:0:0:0:0:1 - - 26/Mar/2021:11:04:36 -0500 "GET /map HTTP/1.1" 200 13 - - - 0:0:0:0:0:0:0:1 - - 26/Mar/2021:11:04:37 -0500 "GET /long HTTP/1.1" 200 6 - - - 0:0:0:0:0:0:0:1 - - 26/Mar/2021:11:04:39 -0500 "GET /string HTTP/1.1" 200 6 6 6 6
Following http://logback.qos.ch/manual/layouts.html, I tried all the conversion word for the content length, "%b", "%B", and "%bytesSent", and they all seem to work and generate the content length, but ONLY if the response return type is "String". They did NOT generate the content length for Map, List or even a Long object.
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.