我開發了一個Web應用程序,我可以註冊一個員工。如何在web.xml和log4j.properties中配置log4j輸出文件路徑?
我web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Employee Registration</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>sapient</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sapient</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
</web-app>
現在,當我點擊我的html頁面一Register
按鈕。它去,我已經寫了日誌記錄的代碼的控制器類,
@org.springframework.stereotype.Controller
public class RegController {
private static final Logger LOGGER = Logger
.getLogger(RegController.class.getName());
@RequestMapping(value = "/register.htm", method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
LOGGER.debug("ENTERING the contoller class");
ModelAndView mav = new ModelAndView("register");
LOGGER.debug("exiting the contoller class");
return mav;
}
}
我創建了一個名爲resource
包,並在
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=1MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
創建log4j.properties文件但我的日誌不是在C:
驅動器中創建的。
我需要在web.xml中配置一些東西嗎? 我已經包含log4j.jar文件。
請參閱此鏈接http://www.mkyong。com/spring-mvc/spring-mvc-log4j-integration-example/ – Swarne27