Log4j.properties file
${project} is configured inside Web.xml
Log4j.rootlogger=info, Stdout,logfile
log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.target=system.out
log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=%d%p-%m%n
log4j.appender.logfile= Org.apache.log4j.RollingFileAppender
Log4j.appender.logfile.file=${project}/web-inf/logs/tjsjbzlog.log
log4j.appender.logfile.append=true
log4j.appender.logfile.maxfilesize=1000kb
Log4j.appender.logfile.maxbackupindex=1
log4j.appender.logfile.layout=org.apache.log4j.patternlayout
log4j.appender.logfile.layout.conversionpattern=%d%p-%m%n
Web.xml file red text, note add log4j Listener
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <display-name></display-name> <!--configuration Log4j-- > <context-param> <param-name>webAppRootKey</param-name> <param-value>project</ param-value><!--log4j configuration file can use ${project} to represent the system variables just set--> </context-param> <context-param> &L T;param-name>log4jconfiglocation</param-name> <param-value>/WEB-INF/classes/log4j.properties< /param-value><!--configuration file path--> </context-param> <context-param> <param-name>
log4jrefreshinterval</param-name><!--Default Reload profile time--> <param-value>3000</param-value> </context-param> <!--load Spring configuration file--> <!--contextloader Loading CONtextconfiglocation used to initialize Webapplicationcontext--> <context-param> <param-name> Contextconfiglocation</param-name> <param-value>/web-inf/classes/applicationcontext.xml</ param-value> </context-param> <listener> <listener-class>
Com.hhkj.tjsjbz.listener.managercontentlistener</listener-class> </listener> <!--log4j listener-->
<listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!--load Spring listener--> <listener> <listener-class>org.springframework.web.conte Xt. Contextloaderlistener</listener-class> </listener> <!--Load Spring's filter agent,
Filter--> <!--beanid for Securityfilter <filter> <filter-name>securityFilter</filter-name> <filter-class>com.hhkj.tjsjbz.filter.SecurityFilter</filter-class> </filter> Filter Mapping ( Filtering on the action must be placed before struts is configured, notHowever not effective) <filter-mapping> <filter-name>securityFilter</filter-name> <url-pattern>*.jsp</ url-pattern> </filter-mapping> <filter-mapping> <filter-name>securityfilter</filter-name
> <url-pattern>*.action</url-pattern> </filter-mapping>--> <!--session timeout definition, in minutes-->
<session-config> <session-timeout>60</session-timeout> </session-config> <filter>
<filter-name>struts2</filter-name> <filter-class> Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> <init-param> &L
T;param-name>actionpackages</param-name> <param-value>com.hhkj.tjsjbz.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <ur L-pattern>/*</url-pattern> </filter-mapping> <WELCOME-FILE-LIST>
<welcome-file>login.action</welcome-file> </welcome-file-list> </web-app>