Running the web project gives the following warning:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Reason: log4j was not found when loading spring's contextLoader.
solve:
- There is no log4j configured in web.xml (add the following code in web.xml)
<!-- log4g log configuration--> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <listener> <description>log4g log loading</description> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener>
- web.xml is configured, but the above warning still exists (that is, put the spring configuration contextConfigLocation after the log4j configuration)
<!-- log4g log configuration--> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j.properties</param-value> </context-param> <listener> <description>log4g log loading</description> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Load spring's xml configuration file into spring's context container --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-*.xml</param-value> </context-param>
Attach log4j.properties
log4j.rootLogger=info,CONSOLE,A log4j.addivity.org.apache = false log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Threshold=DEBUG log4j.appender.CONSOLE.layout.ConversionPattern=%c %d{yyyy-MM-dd HH\:mm\:ss} -%-4r [%t] %-5p %x - %m%n log4j.appender.CONSOLE.Target=System.out log4j.appender.CONSOLE.Encoding=gbk log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.A = org.apache.log4j.DailyRollingFileAppender log4j.appender.A.File=${catalina.home}/logs/jeef_log/PurePro_ log4j.appender.A.DatePattern=yyyy-MM-dd'.log' log4j.appender.A.layout=org.apache.log4j.PatternLayout log4j.appender.A.layout.ConversionPattern= %d{yyyy-MM-dd HH\:mm\:ss} %5p %c{1}\:%L \: %m%n