From b427681a8a9799248cb9a19de752583e8d6c363d Mon Sep 17 00:00:00 2001 From: jshixiong Date: Wed, 1 Feb 2023 14:16:36 +0800 Subject: [PATCH] logback --- .../controller/HelloController.java | 5 +- src/main/resources/application.properties | 4 ++ src/main/resources/logback-spring.xml | 55 ++++++++++++------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/example/test/jsxtestttt/controller/HelloController.java b/src/main/java/com/example/test/jsxtestttt/controller/HelloController.java index 0bd6ad8..fe53a85 100644 --- a/src/main/java/com/example/test/jsxtestttt/controller/HelloController.java +++ b/src/main/java/com/example/test/jsxtestttt/controller/HelloController.java @@ -12,12 +12,13 @@ public class HelloController { @GetMapping("/") public String index() { - logger.info("a log : web greetings from Spring Boot"); + logger.info("a log : Greetings from Spring Boot"); return "Greetings from Spring Boot!"; } @GetMapping("/healthcheck") public String healthcheck() { - return "Greetings from Spring Boot!"; + logger.error("a log : Call error"); + return "Greetings from Spring Boot! Call error"; } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8871991..94a1f40 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,6 @@ server.port=8881 + logging.config=classpath:logback-spring.xml +log.path=logs +# FALSE同步;FILE异步 +log.async.file=FILE diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index b54eaae..8dde5fb 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,6 +1,7 @@ - + + @@ -8,22 +9,40 @@ ${logPattern} - - - - + + + - - - - - - - - - + + + ${logPattern} + UTF-8 + + + ${logPath}/demolog.%d{yyyy-MM-dd}-%i.log + 7 + 100MB + 1GB + + --> + ERROR + + + + + + 0 + + 512 + + false + + false + + + @@ -40,18 +59,16 @@ - - - - + + - +