Class AuditLogAPMEventListener
java.lang.Object
tech.riemann.nif.apm.event.APMEventListener
tech.riemann.nif.apm.event.AbstractAuditLogAPMEventListener
tech.riemann.nif.apm.event.AuditLogAPMEventListener
- All Implemented Interfaces:
EventListener, org.springframework.context.ApplicationListener<APMEvent>
审计日志APM事件监听器实现类
继承自AbstractAuditLogAPMEventListener,提供默认的审计日志处理逻辑
主要功能: 1. 从Swagger注解中提取业务模块标签(@Tag.description) 2. 从Swagger注解中提取业务操作名称(@Operation.summary) 3. 根据@APMIgnore注解或Swagger注解是否存在来决定是否跳过记录 4. 使用Nutz Dao进行数据库操作(创建表和插入数据)
跳过记录的条件: - 方法为null - 方法标记了@APMIgnore注解 - 无法从@Tag注解获取业务模块标签 - 无法从@Operation注解获取业务操作名称
使用场景: - 适用于使用Swagger/OpenAPI注解的项目 - 可以直接复用,无需自定义实现
- Author:
- Kerbores(kerbores@riemann.tech)
-
Constructor Summary
ConstructorsConstructorDescriptionAuditLogAPMEventListener(org.nutz.dao.Dao dao, String application, TableSuffixProvider tableSuffixProvider, boolean writeToDatabase) 构造审计日志监听器 -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateTable(String suffix) 创建审计日志分表boolean判断是否跳过记录审计日志operationName(@Nullable Class<?> clazz, @Nullable Method method) 获取业务操作名称void保存审计日志获取业务模块标签Methods inherited from class AbstractAuditLogAPMEventListener
beforeSave, handleAPMLog, handleAPMLog, init, isSpringMvcBuiltInObject, toString, toStringMethods inherited from class APMEventListener
onApplicationEventMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecution
-
Constructor Details
-
AuditLogAPMEventListener
public AuditLogAPMEventListener(org.nutz.dao.Dao dao, String application, TableSuffixProvider tableSuffixProvider, boolean writeToDatabase) 构造审计日志监听器- Parameters:
dao- Nutz Dao对象application- 应用名称tableSuffixProvider- 表名后缀提供者writeToDatabase- 是否将审计日志写入数据库
-
-
Method Details
-
tagName
获取业务模块标签从类的@Tag注解中提取description作为业务模块标签
- Specified by:
tagNamein classAbstractAuditLogAPMEventListener- Parameters:
clazz- 类method- 方法- Returns:
- 业务模块标签,如果无法获取则返回空字符串
-
operationName
获取业务操作名称从方法的@Operation注解中提取summary作为业务操作名称
- Specified by:
operationNamein classAbstractAuditLogAPMEventListener- Parameters:
clazz- 类method- 方法- Returns:
- 业务操作名称,如果无法获取则返回空字符串
-
ignore
判断是否跳过记录审计日志跳过条件: 1. 方法为null 2. 方法标记了@APMIgnore注解 3. 无法获取业务模块标签(tagName为空) 4. 无法获取业务操作名称(operationName为空)
- Specified by:
ignorein classAbstractAuditLogAPMEventListener- Parameters:
log- APM日志clazz- 类method- 方法- Returns:
- true表示跳过,false表示记录
-
createTable
创建审计日志分表使用Nutz Dao根据AuditLog实体类创建表结构
M30: 同一分表后缀只建一次——已建表直接跳过 DDL,避免每条日志重复建表
- Specified by:
createTablein classAbstractAuditLogAPMEventListener- Parameters:
suffix- 表名后缀
-
saveLog
保存审计日志使用Nutz Dao将审计日志插入到数据库
- Specified by:
saveLogin classAbstractAuditLogAPMEventListener- Parameters:
suffix- 表名后缀log- 审计日志对象
-