- 日志,log4j2日志
日志的五种级别 - 多个日志文件之间可能存在冲突,这时候就需要进行配置,在pom.xml中
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-loggin</artifactId>
</exclusion>
</exclusions>
排除日志的冲突,后续重新引入自身的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
会根据springboot的内容自己找到对应的版本
引入以后就要对其进行配置,在resource中进行配置
<Properties>
<Property name="baseDir" value="D:\java\code\logs"/>
</Properties>
这是配置日志存放的位置
3. AOP统一处理web日志请求:真实的项目都会有`
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
首先引入aop的依赖
拦截器:请求之前和请求之后
@AfterReturning(returning = "res", pointcut = "webLog()")
public void doAfterReturning(Object res) throws JsonProcessingException {
//处理完请求,返回内容
log.info("RESPONSE : " + new ObjectMapper().writeValueAsString(res));
}
new ObjectMapper():可以把对象转化成json