请求日志单独保存

 将请求日志单独保存至一个独立的日志文件中,方便后期的维护及错误查找。(项目中使用logback进行日志管理)

1.在logback.xml中添加“REQUEST_FILE“的配置:

 1 <appender name="REQUEST_FILE"
 2         class="ch.qos.logback.core.rolling.RollingFileAppender">
 3         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
 4             <level>INFO</level>
 5         </filter>
 6         <File>${LOG_PATH}/request/request.log</File>
 7         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
 8             <fileNamePattern>${LOG_PATH}/request/request-%d{yyyyMMdd}.log.%i
 9             </fileNamePattern>
10             <timeBasedFileNamingAndTriggeringPolicy
11                 class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
12                 <maxFileSize>500MB</maxFileSize>
13             </timeBasedFileNamingAndTriggeringPolicy>
14             <maxHistory>30</maxHistory>
15         </rollingPolicy>
16         <layout class="ch.qos.logback.classic.PatternLayout">
17             <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}-%msg%n</Pattern>
18         </layout>
19         <filter class="ch.qos.logback.classic.filter.LevelFilter">  
20             <level>INFO</level>  
21         </filter>
22     </appender>
REQUEST_FILE 配置

2.在<root>中添加“REQUEST_FILE“的配置:

3.添加“REQUEST_FILE“的<logger>配置:

<logger name="request" additivity="false">

      <appender-ref ref="REQUEST_FILE"/>
</logger>

4. 在代码中添加request的配置(request对应于第三步中的logger.name)

private Logger monitorLogger = LoggerFactory.getLogger("request");

 

posted @ 2017-08-07 13:34  染颜  阅读(384)  评论(0编辑  收藏  举报