我已将log4j.xml
.WEB-INF/classes/log4j.xml
我log4j.xml
的是,
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" > -->
<appender name="fileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="INFO" />
<param name="MaxFileSize" value="512KB" />
<param name="MaxBackupIndex" value="10" />
<param name="File" value="F:/Spring_logs/pointel_Aop.log" />
<!-- <param name="File" value="${webapp.root}/WEB-INF/logs/helloworld.log" /> -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %c{1}:%L %m %n" />
</layout>
</appender>
<!--sets the priority log level for org.springframework -->
<logger name="org.springframework">
<level value="info" />
</logger>
<!--sets the priority log level for com.pointel.EM.controllers -->
<logger name="com.pointel.EM.controllers">
<level value="debug" />
</logger>
<!--sets the default priority log level -->
<root>
<priority value="info"></priority>
<appender-ref ref="fileAppender" />
</root>
</log4j:configuration>
在我的web.xml
,
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
在我的controller
,
@Controller
public class PageController {
Logger logger = Logger.getLogger(PageController.class);
@RequestMapping(value="index.html" , method=RequestMethod.GET)
public String indexPage(){
//logger.log(Level.DEBUG,"Entered in the GET of index.html");
logger.trace("Trace..............");
logger.debug("Debug...............");
System.out.println("Index Page............");
return "Main";
}
}
日志文件将在log4j.xml
. 但是日志信息不会打印在日志文件中。
在创建的日志文件中,
2013-04-02 14:36:32,945 INFO DispatcherServlet:301 FrameworkServlet 'dispatcher': initialization started
2013-04-02 14:36:32,976 INFO XmlWebApplicationContext:456 Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Apr 02 14:36:32 GMT+05:30 2013]; root of context hierarchy
2013-04-02 14:36:33,023 INFO XmlBeanDefinitionReader:315 Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
2013-04-02 14:36:33,367 INFO DefaultListableBeanFactory:549 Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@171f189: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,pageController,viewResolver,messageSource]; root of factory hierarchy
2013-04-02 14:36:33,445 INFO DefaultAnnotationHandlerMapping:411 Mapped URL path [/index.html] onto handler [com.pointel.EM.controllers.PageController@11db6bb]
2013-04-02 14:36:33,445 INFO DefaultAnnotationHandlerMapping:411 Mapped URL path [/Main.jsp] onto handler [com.pointel.EM.controllers.PageController@11db6bb]
2013-04-02 14:36:33,445 INFO DefaultAnnotationHandlerMapping:411 Mapped URL path [/addEmployee.html] onto handler [com.pointel.EM.controllers.PageController@11db6bb]
2013-04-02 14:36:33,445 INFO DefaultAnnotationHandlerMapping:411 Mapped URL path [/listEmployees.html] onto handler [com.pointel.EM.controllers.PageController@11db6bb]
2013-04-02 14:36:33,476 INFO Version:56 Hibernate Validator 4.0.2.GA
2013-04-02 14:36:33,476 INFO DefaultTraversableResolver:89 Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
2013-04-02 14:36:33,632 INFO DispatcherServlet:320 FrameworkServlet 'dispatcher': initialization completed in 687 ms
Index page ........
将在控制台打印以确认控制器的条目。
任何人都可以帮助打印日志文件中的日志信息。
好的答案绝对值得赞赏。谢谢。