1、引入依賴
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
2、簡介
Spring Boot默認使用LogBack日誌系統
日誌級別
TRACE < DEBUG < INFO < WARN < ERROR < FATAL
package com.asiainfo.group.servicea.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/log")
public class LogController {
//LogController.class可有可無,因爲隨便寫個其他類也不會報錯,但準確編寫class信息能夠提供快速定位日誌的效率
private static final Logger logger = LoggerFactory.getLogger(LogController.class);
@RequestMapping("/printLog")
public String printLog(String log){
//日誌級別TRACE < DEBUG < INFO < WARN < ERROR < FATAL
logger.trace("trace:"+log);
logger.debug("debug:"+log);
logger.info("info:"+log);
logger.warn("warn:"+log);
logger.error("error:"+log);
return "日誌打印成功!";
}
}
logging:
level:
#所有的
root: info
#特定包
com.asiainfo.group.servicea.controller: debug