1 year ago

#296172

test-img

motobói

Pring log messages grouped by request in spring boot

I have a Spring Boot application with a very high request rate.

This application do a lot of steps and those steps' log messages become garbled and mixed.

[DEBUG] - Done step1 for user A
[DEBUG] - Step 1 for user A took X seconds 
[DEBUG] - Done step1 for user B
[DEBUG] - Step 2 for user A took X seconds 
[DEBUG] - Step 1 for user B took X seconds 
[DEBUG] - Step 2 for user B took X seconds 
[DEBUG] - Step 3 hit special case for user B
[DEBUG] - Step 3 hit special case for user A
[DEBUG] - Total processing time for user A is XXXX
[DEBUG] - Total processing time for user B is XXXX

I would like to accumulate log messages and print them at the end for the processing.

Something like:

[DEBUG] - Done step1 for user A
[DEBUG] - Step 1 for user A took X seconds 
[DEBUG] - Step 2 for user A took X seconds 
[DEBUG] - Step 3 hit special case for user A
[DEBUG] - Total processing time for user A is XXXX
[DEBUG] - Done step1 for user B
[DEBUG] - Step 1 for user B took X seconds 
[DEBUG] - Step 2 for user B took X seconds 
[DEBUG] - Step 3 hit special case for user B
[DEBUG] - Total processing time for user B is XXXX

Is that possible with spring boot?

Currently, I'm accumulating all log messages in a StringBuilder, but I have to pass this object around on all calls. This is very cumbersome take a heavy toll on readability.

java

spring

spring-boot

logging

java.util.logging

0 Answers

Your Answer

Accepted video resources