Skip to content
Advertisement

Why is Log4j2 not logging inside Spring Boot Application?

I’m trying to use spring boot starter and spring boot starter web. So far I’ve got what I think is a pretty simple set up. I can see that the application is obviously finding and using the log4j2-spring.xml file so my question is why doesn’t anything from the MyRunner class log via log4j2? It does execute and the System.out.println() statements are writing to the console but the LOG.error messages are not. Please help.

pom.xml:

JavaScript

log4j2-spring.xml:

JavaScript

Application.java:

JavaScript

Console Output:

JavaScript

Advertisement

Answer

I tried your code with few changes to work on my IDE, and it is working perfectly fine, below is the updated code, this code may help you to dig down your issue:

JavaScript

I have kept below log xml(log4j2-spring.xml) under – src/main/resource

JavaScript

Removed mybatis and jdbc dependencies as spring was asking for db configuration. Those Jar might be causing the issues in your code(overriding your log configurations):

JavaScript

output:

JavaScript

This might not be your solution, but will help you to find the issue.

Adding code in Answer section as cant explain in comment section

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement