简体   繁体   中英

Logs are not printing

I am currently working on a project which has spring used in it. For Junit, i am using @RunWith(SpringJUnit4ClassRunner.class) annotation. Everything is working fine except I do not see any logs for spring processing of applicationContext. In the console window, this is a current message :

log4j:WARN No appenders could be found for logger (org.springframework.test.context.support.DefaultTestContextBootstrapper).
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 kept the log4j.properties in src/main/resources folder of Eclipse(Using a maven project). Following are the contents :

Log4j.properties ;

# Root logger option
log4j.rootLogger=INFO

log4j.appender.stdout=org.apache.log4j.ConsoleAppender 
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p\t%d{ISO8601}\t%r\t%c
\t[%t]\t%m%n

Have looked at already raised Q/A regarding similar issues. But still no clue about what is the issue. Could anyone here help me please in this ?

Thanks

You need to specify the where the log4j properties are stored as a context param of your spring application. You can done by adding the following part inside your web.xml. Make sure you bundle log4j.properties file inside your /WEB-INF/classes/ directory.

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM