【struts2】配置log4j,设置日志文件保存路径

时间:2022-12-22 18:06:45
  1. 到pom.xml添加log4j dependency
    1         <groupId>log4j</groupId>
    2             <artifactId>log4j</artifactId>
    3             <version>${log4j.version}</version>
    4         </dependency>

     

  2. 到classpath下,如src/main/resources下添加log4j.properties
     1 log4j.projectName=log4j-test-webapp
     2 log4j.rootLogger=DEBUG, FILE
     3 
     4 # define the appender
     5 log4j.appender.FILE=org.apache.log4j.FileAppender
     6 log4j.appender.FILE.File=${catalina.home}/logs/${log4j.projectName}.log
     7 
     8 # define the layout
     9 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
    10 log4j.appender.FILE.layout.conversionPattern=%d %5p (%c:%L) - %m%n

    其中用于保存log的日志文件位于tomcat下的logs目录。命名为项目名称.log