master
冯凯 2023-11-22 11:07:00 +08:00
parent ae904c52cf
commit 3609c6ecf2
2 changed files with 12 additions and 1 deletions

View File

@ -8,7 +8,7 @@
<version>3.6.4</version> <version>3.6.4</version>
</parent> </parent>
<!--chongxin--> <!--chongxin-->
<version>3.6.4</version> <version>3.6.5</version>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>dragon-common-log</artifactId> <artifactId>dragon-common-log</artifactId>

View File

@ -23,6 +23,9 @@ import org.springframework.core.NamedThreadLocal;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -56,6 +59,12 @@ public class LogAspect {
*/ */
@Before(value = "@annotation(controllerLog)") @Before(value = "@annotation(controllerLog)")
public void boBefore(JoinPoint joinPoint, Log controllerLog) { public void boBefore(JoinPoint joinPoint, Log controllerLog) {
ServletRequestAttributes attributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
log.info("========================================== Start ==========================================");
log.info("URL:{}",request.getRequestURL().toString());
log.info("method:{}",request.getMethod());
log.info("请求ip是:",request.getRemoteAddr());
TIME_THREADLOCAL.set(System.currentTimeMillis()); TIME_THREADLOCAL.set(System.currentTimeMillis());
} }
@ -67,6 +76,8 @@ public class LogAspect {
@AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult") @AfterReturning(pointcut = "@annotation(controllerLog)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) { public void doAfterReturning(JoinPoint joinPoint, Log controllerLog, Object jsonResult) {
handleLog(joinPoint, controllerLog, null, jsonResult); handleLog(joinPoint, controllerLog, null, jsonResult);
// 接口结束后换行,方便分割查看
log.info("=========================================== End ===========================================");
} }
/** /**