一、application.properties/application.yml
#不同目录下的日志可配置不同级别
#logging.level.root= warn
#logging.level.org-springframework-web=debug
#logging.level.org-hibernate= error
#采用相对路径方式将日志文件输出到【projectlog/project.log】
logging.file.name= projectlog/project.log
logging.file.max-history=100
#自定义日志输出格式
logging.pattern.console= %d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n
logging.pattern.file=%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n
或者
logging:
#level:
# root: "warn"
# org.springframework.web: "debug"
# org.hibernate: "error"
file:
name: projectlog/project.log
max-history: 100
pattern:
console: "%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n"
file: "%d{yyyy-/MM-/dd HH:mm:ss} [%thread] %-5level %logger- %msg%n"
二、测试并输出日志:
package com.kd.demo.mapper;
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;
@SpringBootTest
@RunWith(SpringRunner.class)
public class LogMapperTest {
protected static final Logger logger = LoggerFactory.getLogger(LogMapperTest.class);
@Test
public void LogTest() {
logger.error("===系统调用了LogMapperTest===");
}
}