diff --git a/spring-boot-log/pom.xml b/spring-boot-log/pom.xml index 059f7db73615f499dd3561ce616ae7aed77c7416..cdd7697fcd3ecaa0e1163a965077c11734de40df 100644 --- a/spring-boot-log/pom.xml +++ b/spring-boot-log/pom.xml @@ -24,6 +24,13 @@ org.springframework.boot spring-boot-starter + + + org.projectlombok + lombok + 1.18.12 + provided + org.springframework.boot diff --git a/spring-boot-log/src/main/resources/application.properties b/spring-boot-log/src/main/resources/application.properties index 8b137891791fe96927ad78e64b0aad7bded08bdc..c9901b083e1755795c97529375cf326730b0903d 100644 --- a/spring-boot-log/src/main/resources/application.properties +++ b/spring-boot-log/src/main/resources/application.properties @@ -1 +1,8 @@ +# 设置日志级别 +logging.level.root=WARN +# 设置日志文件 +logging.file=C:\\logs\\spring-boot-log.log + +# 设置日志目录 +logging.path=C:\\logs diff --git a/spring-boot-log/src/test/java/com/imooc/springbootlog/LogTest.java b/spring-boot-log/src/test/java/com/imooc/springbootlog/LogTest.java new file mode 100644 index 0000000000000000000000000000000000000000..f50b94b6f6e6e26827591960eaca4aaff1de5e51 --- /dev/null +++ b/spring-boot-log/src/test/java/com/imooc/springbootlog/LogTest.java @@ -0,0 +1,25 @@ +package com.imooc.springbootlog; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.context.SpringBootTest; + +import lombok.extern.slf4j.Slf4j; + +@SpringBootTest +@Slf4j // 添加日志输出注解 +class LogTest { + // 不再需要定义 logger + // private Logger logger = LoggerFactory.getLogger(this.getClass()); + + @Test + void testPrintLog() { + // 直接使用log输出日志 + log.trace("trace log"); + log.debug("debug log"); + log.info("info log"); + log.warn("warn log"); + log.error("error log"); + } +} \ No newline at end of file diff --git a/spring-boot-log/src/test/java/com/imooc/springbootlog/SpringBootLogApplicationTests.java b/spring-boot-log/src/test/java/com/imooc/springbootlog/SpringBootLogApplicationTests.java deleted file mode 100644 index e4a48288d0aec46176a0b2212cf8c3e7bf1b4c02..0000000000000000000000000000000000000000 --- a/spring-boot-log/src/test/java/com/imooc/springbootlog/SpringBootLogApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.imooc.springbootlog; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SpringBootLogApplicationTests { - - @Test - void contextLoads() { - } - -}