1 spring boot-Log 日志 pom.xml
<!-- Exclude Spring Boot's Default Logging --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <!-- Add Log4j2 Dependency --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency>
2日志代码 测试
package com.example.demo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @Controller public class User { private static final Logger logger; static { logger = LogManager.getLogger(User.class); } @RequestMapping("/user") @ResponseBody public String ShowHelloWorld() { logger.error("开始"); return "HelloWorld"; } }
测试结果 :2019-02-23 16:43:05.787 ERROR 768 --- [nio-8080-exec-1] c.e.d.User : 开始