web项目中添加logger日志

在项目中添加log4j.xml文件

log4j.xml文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
 <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
  <param name="Threshold" value="info" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="[%-d{HH:mm:ss}][ld_safeservice] %p [%t] %c{1}.%M(%L) | %m%n" />
  </layout>
 </appender>
 <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="Threshold" value="info" />
  <param name="File" value="../logs/ld_safeservice.log" />
  <param name="maxFileSize" value="10MB" />
    <param name="maxBackupIndex" value="5" />
  <param name="Append" value="true" />
  <param name="DatePattern" value="‘.‘yyyy-MM-dd" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern"
    value="[%-d{HH:mm:ss}][ld_safeservice1] %p [%t] %c{1}.%M(%L) | %m%n" />
  </layout>
 </appender>
 

 <appender name="IBatis" class="org.apache.log4j.ConsoleAppender">
    <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern"
      value="%-4r [%t] %-5p %c %x - %m%n" />
    </layout>
    <filter class="org.apache.log4j.varia.LevelRangeFilter">
     <param name="LevelMin" value="DEBUG" />
     <param name="LevelMax" value="DEBUG" />
    </filter>
   </appender>
  
 <root>
  <priority value="info" />
  <appender-ref ref="FILE" />
  <appender-ref ref="CONSOLE" />
 </root>

</log4j:configuration>

 

web.xml中添加配置

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

 

java类中添加

static final Logger LOGGER = Logger.getLogger(SafeVisitController.class);

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。