mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-11 06:57:14 +08:00
refactor(log): 抽取 isRecord 方法方便复用,移除已过期的 timeTtl
This commit is contained in:
@@ -36,11 +36,6 @@ import java.net.URISyntaxException;
|
||||
/**
|
||||
* 日志过滤器
|
||||
*
|
||||
* @author Dave Syer(Spring Boot Actuator)
|
||||
* @author Wallace Wadge(Spring Boot Actuator)
|
||||
* @author Andy Wilkinson(Spring Boot Actuator)
|
||||
* @author Venil Noronha(Spring Boot Actuator)
|
||||
* @author Madhura Bhave(Spring Boot Actuator)
|
||||
* @author Charles7c
|
||||
* @author echo
|
||||
* @since 1.1.0
|
||||
|
@@ -20,6 +20,7 @@ import cn.hutool.core.annotation.AnnotationUtil;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import io.swagger.v3.oas.annotations.Hidden;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.slf4j.Logger;
|
||||
@@ -49,6 +50,29 @@ public abstract class AbstractLogHandler implements LogHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractLogHandler.class);
|
||||
private final TransmittableThreadLocal<AccessLogContext> logContextThread = new TransmittableThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public boolean isRecord(Method targetMethod, Class<?> targetClass) {
|
||||
// 如果接口被隐藏,不记录日志
|
||||
Operation methodOperation = AnnotationUtil.getAnnotation(targetMethod, Operation.class);
|
||||
if (null != methodOperation && methodOperation.hidden()) {
|
||||
return false;
|
||||
}
|
||||
Hidden methodHidden = AnnotationUtil.getAnnotation(targetMethod, Hidden.class);
|
||||
if (null != methodHidden) {
|
||||
return false;
|
||||
}
|
||||
if (null != targetClass.getDeclaredAnnotation(Hidden.class)) {
|
||||
return false;
|
||||
}
|
||||
// 如果接口方法或类上有 @Log 注解,且要求忽略该接口,则不记录日志
|
||||
Log methodLog = AnnotationUtil.getAnnotation(targetMethod, Log.class);
|
||||
if (null != methodLog && methodLog.ignore()) {
|
||||
return false;
|
||||
}
|
||||
Log classLog = AnnotationUtil.getAnnotation(targetClass, Log.class);
|
||||
return null == classLog || !classLog.ignore();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LogRecord.Started start(Instant startTime) {
|
||||
return LogRecord.start(startTime);
|
||||
|
@@ -33,6 +33,15 @@ import java.util.Set;
|
||||
*/
|
||||
public interface LogHandler {
|
||||
|
||||
/**
|
||||
* 是否记录日志
|
||||
*
|
||||
* @param targetMethod 目标方法
|
||||
* @param targetClass 目标类
|
||||
* @return 是否记录日志
|
||||
*/
|
||||
boolean isRecord(Method targetMethod, Class<?> targetClass);
|
||||
|
||||
/**
|
||||
* 开始日志记录
|
||||
*
|
||||
|
Reference in New Issue
Block a user