How to fix log4j:WARN console messages when running an Application inside IntelliJ Idea Follow
I have noticed the appearance of some log4j warnings when I was running a simple spring application.
These messages are like this :
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
To fix that just enter the following log4j.resources file into main/resources folder of your project :
# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
Of course this is a fix that can be applied to the next IntelliJ IDE version, so that the user is not faced with these annoying errors.
Update : If you want to just supress the error messsages use the following line in your starting class
Logger.getRootLogger().setLevel(Level.OFF);
Please sign in to leave a comment.
Could you post full command-line incl. classpath of your application console? Why do you think this is caused by IntelliJ IDEA? Thanks.
Of course.
Here it goes.
AFAIU the message was caused by missing log4.xml, which according to
is the expected behaviour (user must provide explicit configuration for logging to work).
You can still add the above mentioned properties file to your next version as a simple default behavior configuration for log4j
In my case I tried to used commons logging but it seems that it is a simple wrapper abstract utility that uses log4j.
IMHO we cannot predict user's needs (some people might even prefer no logging at all when starting from IDE), so the current way of manual/explicit configuration seems the most useful to me.
it works for me, thank you
For me it worked when the file is named as "log4j.properties" instead of "log4j.resources" in main/resources/ folder of project.