log4j.xml - WARN No appenders could be found for logger

log4j, xml

Solution

Your log4j.xml file needs to go in the directory src/main/resources. Log4J is expecting to find it at the root of the classpath.

The resources directory is the place to put everything that is not Java code, but which you want to go into the classpath. If it's something only tests should use, put it in src/test/resources, otherwise use src/main/resources.

Problem

I ltried to use `log4j` loger for my simple project. But when I run project I cought strainge warning from log4j at console: ``` log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager). 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 couldn't figure out why exactly this happen. I added and downloaded log4j with Maven all should work. I specified apeender, to my mind ok it should work correctly. But as you can see it isn't. Here is content of my `log4j.xml`: ``` <!-- Appenders --> <!-- Loggin into console --> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p: %c - %m%n" /> </layout> </appender> <appender name="file" class="org.apache.log4j.DailyRollingFileAppender"> <param name="file" value="/logs/log.log" /> <param name="DatePattern" value="'.'yyyy-MM-dd" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p (%F:%L:%M) %c{1} - %m%n" /> </layout> </appender> <!-- Root logger --> <root> <priority value="info" /> <appender-ref ref="file" /> <appender-ref ref="console" /> </root> <!-- Application Loggers --> <logger name="com.softserve.edu"> <level value="info" /> </logger> ``` I missed standart header and footer ( tags). One slippery palce is that this file into `logs` folder doesn't exist (I guess that log4j will create it by itself). Here is my project struckture: UPDATE: I created new folder under `src/test/resources` and moved `log4j.xml` into. Now all are ok with this WARNING but `log` file doesn't created. what is wrong with this line `<param name="file" value="/logs/log.log" />` ? - How to solve this trouble?

Original source