spring boot项目记录--日志处理

微信点餐用到的日志框架:slf4j(门面)+logback(框架)

@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class  LogTest {
    @Test
    public void test1(){
        String name ="imooc";
        String password = "1223";
        log.debug("debug...");
        log.info("name:{},  password:{}",name,password);
        log.error("error...");

    }
}

对于日志文件的配置:

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 
 3 <configuration>
 4 //内容展示形式
 5     <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
 6         <layout class = "ch.qos.logback.classic.PatternLayout">
 7             <pattern>
 8                 %d - %msg%n
 9             </pattern>
10         </layout>
11     </appender>
12 
13 //针对不同级别输出到不同文件里 
14     <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
15 
16         <!--过滤器,刨除error级别-->
17         <filter class="ch.qos.logback.classic.filter.LevelFilter">
18             <level>ERROR</level>
19             <onMatch>DENY</onMatch>
20             <onMismatch>ACCEPT</onMismatch>
21         </filter>
22         <encoder>
23             <pattern>
24                 %msg%n
25             </pattern>
26         </encoder>
27         <!--滚动策略-->
28         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
29             <fileNamePattern>H:\self\log\info.%d.log</fileNamePattern>
30         </rollingPolicy>
31     </appender>
32 
33     <appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
34 
35         <!--过滤器,保留error及以上-->
36         <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
37             <level>ERROR</level>
38         </filter>
39         <encoder>
40             <pattern>
41                 %msg%n
42             </pattern>
43         </encoder>
44         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
45             <fileNamePattern>H:\self\log\error.%d.log</fileNamePattern>
46         </rollingPolicy>
47     </appender>
48 //项目适用root(全项目适用),适用级别为“info”
49 <root level="info"> 50 <appender-ref ref="consoleLog"/> 51 <appender-ref ref="fileInfoLog"/> 52 <appender-ref ref="fileErrorLog"/> 53 </root> 54 55 56 </configuration>

 

posted @ 2019-11-06 20:27  lvoooop  阅读(239)  评论(0编辑  收藏  举报