mirror of
https://github.com/continew-org/continew-starter.git
synced 2026-01-17 06:57:09 +08:00
revert(log): 还原 RecordableHttpRequest、RecordableHttpResponse
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package top.continew.starter.log.aspect;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
@@ -23,6 +25,8 @@ import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import top.continew.starter.log.handler.LogHandler;
|
||||
import top.continew.starter.log.http.servlet.RecordableServletHttpRequest;
|
||||
import top.continew.starter.log.http.servlet.RecordableServletHttpResponse;
|
||||
import top.continew.starter.log.model.AccessLogContext;
|
||||
import top.continew.starter.log.model.LogProperties;
|
||||
|
||||
@@ -103,16 +107,22 @@ public class AccessLogAspect {
|
||||
if (attributes == null) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
HttpServletResponse response = attributes.getResponse();
|
||||
try {
|
||||
// 开始访问日志记录
|
||||
logHandler.accessLogStart(AccessLogContext.builder()
|
||||
.startTime(startTime)
|
||||
.request(new RecordableServletHttpRequest(request))
|
||||
.properties(logProperties)
|
||||
.build());
|
||||
return joinPoint.proceed();
|
||||
} finally {
|
||||
Instant endTime = Instant.now();
|
||||
logHandler.accessLogFinish(AccessLogContext.builder().endTime(endTime).build());
|
||||
logHandler.accessLogFinish(AccessLogContext.builder()
|
||||
.endTime(endTime)
|
||||
.response(new RecordableServletHttpResponse(response))
|
||||
.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package top.continew.starter.log.aspect;
|
||||
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@@ -27,6 +29,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import top.continew.starter.core.util.ServletUtils;
|
||||
import top.continew.starter.log.annotation.Log;
|
||||
import top.continew.starter.log.dao.LogDao;
|
||||
import top.continew.starter.log.handler.LogHandler;
|
||||
@@ -75,6 +78,7 @@ public class LogAspect {
|
||||
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Instant startTime = Instant.now();
|
||||
// 指定规则不记录
|
||||
HttpServletRequest request = ServletUtils.getRequest();
|
||||
Method targetMethod = this.getMethod(joinPoint);
|
||||
Class<?> targetClass = joinPoint.getTarget().getClass();
|
||||
if (!isRecord(targetMethod, targetClass)) {
|
||||
@@ -82,7 +86,7 @@ public class LogAspect {
|
||||
}
|
||||
String errorMsg = null;
|
||||
// 开始记录
|
||||
LogRecord.Started startedLogRecord = logHandler.start(startTime);
|
||||
LogRecord.Started startedLogRecord = logHandler.start(startTime, request);
|
||||
try {
|
||||
// 执行目标方法
|
||||
return joinPoint.proceed();
|
||||
@@ -92,7 +96,8 @@ public class LogAspect {
|
||||
} finally {
|
||||
try {
|
||||
Instant endTime = Instant.now();
|
||||
LogRecord logRecord = logHandler.finish(startedLogRecord, endTime, logProperties
|
||||
HttpServletResponse response = ServletUtils.getResponse();
|
||||
LogRecord logRecord = logHandler.finish(startedLogRecord, endTime, response, logProperties
|
||||
.getIncludes(), targetMethod, targetClass);
|
||||
// 记录异常信息
|
||||
if (errorMsg != null) {
|
||||
|
||||
Reference in New Issue
Block a user