0
votes

I am using a Spring boot app with log4j logging enabled. All is well when I run my Spring boot app, I see the log lines in the correct layout. However, when I run a test, I get:

log4j:WARN No appenders could be found for logger (be.delijn.ritsimulator.util.LoadTimeTest). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I have tried moving the log4j2.xml file to every possible place on the classpath but I cannot seem to resolve this issue. I placed it in the root, under resources etc. I just want to be able to have 1 log4j2.xml file instead of one for main and one for test. Also, I do not want to set it using the system property.

Is this possible? If so, how can I achieve this?

Thanks in advance! Regards

1
how do you run your tests?Amer Qarabsa
Via Intellij > Run Test (Ctrl + Shift + F10)Homewrecker
you do not override any vm arguments? what tests are you running? any special configurations for tests?Amer Qarabsa
I do not have any VM arguments set. The tests are plain old jUnit tests that do not have any special configuration.Homewrecker
your tests under src/test?Amer Qarabsa

1 Answers

3
votes

The warning you are seeing is a Log4j 1.2 warning. Somewhere in your classpath there’s a log4j-1.2.x.jar that gets loaded before the Log4j2 jars. This is not good.

Please remove the log4j-1.2.x.jar and add the log4j-1.2-api-2.x.jar: this is a compatibility jar that will route log4j 1.2 API calls to the Log4j2 implementation.