在代码中使用日志,只需要使用如下代码:
private Logger logger = LoggerFactory.getLogger(this.getClass()); //... logger.debug("this is debug"); logger.info("this is info"); 三、Log4j2集成 3.1 配置依赖组件Spring Boot添加Log4j2依赖的同时,需要排除Logback依赖,配置pom.xml代码如下:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions><!-- 去掉logback配置 --> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <!-- 引入log4j2依赖 --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> </dependencies> 3.2 自定义日志配置