The logback console appender configured in https://github.com/spring-projects/spring-boot/blob/e73ee7b3fe2679e67685c3672493f9f9a9f9406f/spring-boot-project/spring-boot/src/main/resources/org/springframework/boot/logging/logback/defaults.xml#L11 logs thread name up to 15 characters: [%15.15t]
causing logged thread names to be incomplete.
The file log pattern logs the full thread name: [%t]
.
Console log pattern should be production ready and expected to be used for log parsing, so it must contain whole information.
Example use case: Using spring boot inside a docker container, the console output will be used by docker logs command and parsed by some log extracting service (elasticsearch filebeat).
Note that console pattern is defined in multiple files.
For finding all files, search for [%15.15t]
in all files.
Comment From: wilkinsona
Thanks for the suggestion.
The use of a limited length for the thread name is intentional as it ensures that each column in the log output is of a fixed width. This ensures that the name of the logger and the message appear in the same place in each line that is logged. This aids human readability which we feel is important for console output.
This is a situation where there's no one answer that will be right for everyone. I can see the benefit of logging the complete thread name for some users but I can also see that it would be a breaking and unwanted change for others. Given that, leaving things as-is feels like the better option.
If you require a particular format for the console log output to meet your parsing requirements, please configure the console log pattern accordingly. You can do so using logging.pattern.console
.
Comment From: cdalexndr
In my opinion, unformatted console log is less important than invalid production logs (docker).
Solution for both worlds is to left pad thread name if < 15 chars, and don't trim longer ones. This can be acomplished using [%15t] that has the behaviour of: Left pad with spaces if the logger name is less than 15 characters long. [%15t] => [____ name] [%15t] => [someverylongthreadname]
Comment From: wilkinsona
Unfortunately, I don't think that [%15t]
is a solution for both worlds. It will be a breaking change for users who want the information that is logged to the right of the thread name to line up and who have one or more threads with a name that's greater than 15 characters in length.