log4j 输出日志文件自定义路径配置

web.xml配置:

 

<!-- log4j配置 -->
 <context-param>
  <param-name>webAppRootKey</param-name>
  <param-value>baseplatform.root</param-value>
 </context-param>

 <context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>
   /WEB-INF/classes/log4j.properties
  </param-value>
 </context-param>
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>

 <servlet>
  <servlet-name>log4j</servlet-name>
  <servlet-class>org.springframework.web.util.Log4jConfigServlet</servlet-class>
  <load-on-startup>-1</load-on-startup>
 </servlet>

 

 

log4j.properties配置:

 

log4j.rootLogger = INFO,CONSOLE,file
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss.SSS} %-5p  %m%n

#file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%-5p][%c:%L][%d{HH:mm:ss,SSS}][%m]%n
log4j.appender.file.DatePattern='-'yyyyMMdd'.log'
log4j.appender.file.Threshold=INFO
log4j.appender.file.File=${baseplatform.root}/logs/baseplatform.log
log4j.appender.file.Encoding=UTF-8
log4j.appender.file.Append=true

 

 

 

 

你可能感兴趣的:(log4j)