SpringBoot日記說明
-
SpringBoot使用的門面是SLF4j,日記實現Logback(相當於接口和實現類的意思)
-
SpringBoot日記的級別由低到高:trace<debug<info<warn<error,如果日誌級別設置爲INFO,則意味TRACE和DEBUG級別的日誌都看不到。
-
可以調整輸出的日記級別,日記就只會在這個級別以後的高級別生效 SpringBoot默認給我們使用的是info級別,沒有指定級別的就用默認的root級別
SpringBoot默認幫我們配置好了日誌,只需要使用就可以了
1、指定日記 logging.level.xx包=trace/debug..(指定了SpringBootApplication註解那個包就可以了)
編寫測試類,打印查看當前配置日記級別
package com.test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class Test2 {
Logger logger = LoggerFactory.getLogger(getClass());
@Test
public void contextLoads() {
logger.trace("trace級別");
logger.debug("debug級別");
logger.info("info級別");
logger.warn("warn級別");
}
}
結果爲
2、指定日記生成路徑 logging.path=/spring/log(一般不使用)
3、指定日記生成文件 logging.file=springboot.log
4、指定在控制檯輸出日記的格式 logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} -%msg%n(格式自己寫)
5、指定在文件中日記輸出的格式 logging.pattern.file=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} -%msg%n
附加信息