Search code examples
spring-bootlog4j2logbackslf4j

SpringBoot - Log4J2 - Redirect Standard Out to log4j2 Pattern


I am trying to redirect the Spring Boot logs to log4j2 but I don't see what I am missing with the configuration.

Notice between A and B, in the Picture 1 below, how the status logs contain some of log entries in my desired pattern but some do not.

In the picture "MYCONFIG > " is a temporary prefix for testing in my pattern.

What I am after is to customize the format of the logs after Spring Boot starts.

Picture 1 - Console Output:

Console Output

Picture 2 - log4j2.properties File

log4j2.properties

What I have looked at so far is this: https://logging.apache.org/log4j/2.x/manual/appenders.html

My test log output shows up in the Spring Boot output through slf4j but not in my desired pattern.

Thanks in advance, Erion


Solution

  • I was able to indirectly solve this issue by simply upgrading to a more recent version of Spring Boot, 2.5.3.

    As part of this I also had to add a direct dependency to the spring-boot-starter-validation library since it is not included as part of spring-boot-starter-web anymore.

    enter image description here