feat: 添加代码格式化
This commit is contained in:
@@ -14,19 +14,23 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@EnableConfigurationProperties(AIOJLogPropertiesConfiguration.class)
|
||||
@ConditionalOnProperty(value = "aioj.log.enabled", matchIfMissing = true)
|
||||
public class LogAutoConfiguration {
|
||||
/**
|
||||
* 创建并返回SysLogListener的Bean实例
|
||||
*/
|
||||
@Bean
|
||||
public SysLogListener sysLogListener(AIOJLogPropertiesConfiguration logProperties, RemoteLogService remoteLogService) {
|
||||
return new SysLogListener(remoteLogService, logProperties);
|
||||
}
|
||||
/**
|
||||
* 返回切面类实例
|
||||
* @return {@link SysLogAspect}
|
||||
*/
|
||||
@Bean
|
||||
public SysLogAspect sysLogAspect() {
|
||||
return new SysLogAspect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建并返回SysLogListener的Bean实例
|
||||
*/
|
||||
@Bean
|
||||
public SysLogListener sysLogListener(AIOJLogPropertiesConfiguration logProperties,
|
||||
RemoteLogService remoteLogService) {
|
||||
return new SysLogListener(remoteLogService, logProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回切面类实例
|
||||
* @return {@link SysLogAspect}
|
||||
*/
|
||||
@Bean
|
||||
public SysLogAspect sysLogAspect() {
|
||||
return new SysLogAspect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,17 @@ import java.lang.annotation.*;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface SysLog {
|
||||
/**
|
||||
* 描述
|
||||
* @return {@link String}
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Spel表达式
|
||||
* @return 日志描述
|
||||
*/
|
||||
String expression() default "";
|
||||
/**
|
||||
* 描述
|
||||
* @return {@link String}
|
||||
*/
|
||||
String value() default "";
|
||||
|
||||
/**
|
||||
* Spel表达式
|
||||
* @return 日志描述
|
||||
*/
|
||||
String expression() default "";
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,18 @@ import org.springframework.expression.EvaluationContext;
|
||||
@RequiredArgsConstructor
|
||||
public class SysLogAspect {
|
||||
|
||||
@Around("@annotation(sysLog)")
|
||||
public Object around(ProceedingJoinPoint joinPoint,SysLog sysLog) throws Throwable {
|
||||
String strClassName = joinPoint.getTarget().getClass().getName();
|
||||
String strMethodName = joinPoint.getSignature().getName();
|
||||
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
|
||||
String value = sysLog.value();
|
||||
String expression = sysLog.expression();
|
||||
if(StrUtil.isNotBlank(expression)) {
|
||||
// 解析SPEL
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
EvaluationContext context = SysLogUtils.getContext(point.getArgs(), signature.getMethod());
|
||||
}
|
||||
}
|
||||
@Around("@annotation(sysLog)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, SysLog sysLog) throws Throwable {
|
||||
String strClassName = joinPoint.getTarget().getClass().getName();
|
||||
String strMethodName = joinPoint.getSignature().getName();
|
||||
log.debug("[类名]:{},[方法]:{}", strClassName, strMethodName);
|
||||
String value = sysLog.value();
|
||||
String expression = sysLog.expression();
|
||||
if (StrUtil.isNotBlank(expression)) {
|
||||
// 解析SPEL
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||
EvaluationContext context = SysLogUtils.getContext(point.getArgs(), signature.getMethod());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,14 +8,17 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
@Setter
|
||||
@ConfigurationProperties(AIOJLogPropertiesConfiguration.PREFIX)
|
||||
public class AIOJLogPropertiesConfiguration {
|
||||
public static final String PREFIX = "aioj.log";
|
||||
/**
|
||||
* 开启日志记录
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 请求报文最大存储长度
|
||||
*/
|
||||
private Integer maxLength = 20000;
|
||||
public static final String PREFIX = "aioj.log";
|
||||
|
||||
/**
|
||||
* 开启日志记录
|
||||
*/
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* 请求报文最大存储长度
|
||||
*/
|
||||
private Integer maxLength = 20000;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,81 +12,82 @@ import java.time.LocalDateTime;
|
||||
@Data
|
||||
public class SysLog implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Long id;
|
||||
/**
|
||||
* 编号
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
private String logType;
|
||||
/**
|
||||
* 日志类型
|
||||
*/
|
||||
private String logType;
|
||||
|
||||
/**
|
||||
* 日志标题
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 日志标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
private String remoteAddr;
|
||||
/**
|
||||
* 操作IP地址
|
||||
*/
|
||||
private String remoteAddr;
|
||||
|
||||
/**
|
||||
* 用户代理
|
||||
*/
|
||||
private String userAgent;
|
||||
/**
|
||||
* 用户代理
|
||||
*/
|
||||
private String userAgent;
|
||||
|
||||
/**
|
||||
* 请求URI
|
||||
*/
|
||||
private String requestUri;
|
||||
/**
|
||||
* 请求URI
|
||||
*/
|
||||
private String requestUri;
|
||||
|
||||
/**
|
||||
* 操作方式
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* 操作方式
|
||||
*/
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* 操作提交的数据
|
||||
*/
|
||||
private String params;
|
||||
/**
|
||||
* 操作提交的数据
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 执行时间
|
||||
*/
|
||||
private Long time;
|
||||
/**
|
||||
* 执行时间
|
||||
*/
|
||||
private Long time;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String exception;
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String exception;
|
||||
|
||||
/**
|
||||
* 服务ID
|
||||
*/
|
||||
private String serviceId;
|
||||
/**
|
||||
* 服务ID
|
||||
*/
|
||||
private String serviceId;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
private String delFlag;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,15 @@ import java.io.Serial;
|
||||
* 系统日志事件类
|
||||
*/
|
||||
public class SysLogEvent extends ApplicationEvent {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**
|
||||
* 构造方法,根据源SysLog对象创建SysLogEvent
|
||||
*/
|
||||
public SysLogEvent(SysLog source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 构造方法,根据源SysLog对象创建SysLogEvent
|
||||
*/
|
||||
public SysLogEvent(SysLog source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ import java.io.Serializable;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SysLogEventSource extends SysLogEvent implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 参数重写成object
|
||||
*/
|
||||
private Object body;
|
||||
/**
|
||||
* 参数重写成object
|
||||
*/
|
||||
private Object body;
|
||||
|
||||
}
|
||||
|
||||
@@ -13,24 +13,27 @@ import org.springframework.scheduling.annotation.Async;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class SysLogListener implements InitializingBean {
|
||||
private final static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final RemoteLogService remoteLogService;
|
||||
private final static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
private final AIOJLogPropertiesConfiguration logProperties;
|
||||
private final RemoteLogService remoteLogService;
|
||||
|
||||
@SneakyThrows
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(SysLogEvent.class)
|
||||
public void saveLog(SysLogEvent sysLogEvent){
|
||||
SysLogEventSource source = (SysLogEventSource) sysLogEvent.getSource();
|
||||
SysLog sysLog = new SysLog();
|
||||
BeanUtils.copyProperties(source, sysLog);
|
||||
private final AIOJLogPropertiesConfiguration logProperties;
|
||||
|
||||
}
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@SneakyThrows
|
||||
@Async
|
||||
@Order
|
||||
@EventListener(SysLogEvent.class)
|
||||
public void saveLog(SysLogEvent sysLogEvent) {
|
||||
SysLogEventSource source = (SysLogEventSource) sysLogEvent.getSource();
|
||||
SysLog sysLog = new SysLog();
|
||||
BeanUtils.copyProperties(source, sysLog);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,13 +6,15 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
|
||||
public class ApplicationLoggerInitializer implements EnvironmentPostProcessor, Ordered {
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Ordered.LOWEST_PRECEDENCE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package cn.meowrain.aioj.backend.framework.log.utils;
|
||||
import cn.meowrain.aioj.backend.framework.log.event.SysLogEventSource;
|
||||
|
||||
public final class SysLogUtils {
|
||||
public static SysLogEventSource getSysLog() {
|
||||
|
||||
}
|
||||
public static SysLogEventSource getSysLog() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user