refactor(ops): 移除旧的publisher模式
- 删除 BusinessLogPublisher 接口 - 删除 DefaultBusinessLogPublisher 实现 - 改用 recorder 模式替代 publisher 模式 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
package com.viewsh.module.ops.infrastructure.log.publisher;
|
||||
|
||||
import com.viewsh.module.ops.infrastructure.log.context.BusinessLogContext;
|
||||
|
||||
/**
|
||||
* 业务日志发布器接口
|
||||
* <p>
|
||||
* 用于发布业务日志,支持异步发布
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
public interface BusinessLogPublisher {
|
||||
|
||||
/**
|
||||
* 发布业务日志
|
||||
*
|
||||
* @param context 日志上下文
|
||||
*/
|
||||
void publish(BusinessLogContext context);
|
||||
|
||||
/**
|
||||
* 异步发布业务日志
|
||||
*
|
||||
* @param context 日志上下文
|
||||
*/
|
||||
void publishAsync(BusinessLogContext context);
|
||||
|
||||
/**
|
||||
* 发布成功日志
|
||||
*
|
||||
* @param context 日志上下文
|
||||
*/
|
||||
void publishSuccess(BusinessLogContext context);
|
||||
|
||||
/**
|
||||
* 发布失败日志
|
||||
*
|
||||
* @param context 日志上下文
|
||||
* @param errorMessage 错误消息
|
||||
*/
|
||||
void publishFailure(BusinessLogContext context, String errorMessage);
|
||||
|
||||
/**
|
||||
* 发布异常日志
|
||||
*
|
||||
* @param context 日志上下文
|
||||
* @param throwable 异常
|
||||
*/
|
||||
void publishError(BusinessLogContext context, Throwable throwable);
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package com.viewsh.module.ops.infrastructure.log.publisher;
|
||||
|
||||
import com.viewsh.module.ops.infrastructure.log.context.BusinessLogContext;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 默认业务日志发布器
|
||||
* <p>
|
||||
* 职责:
|
||||
* 1. 发布业务日志到日志系统
|
||||
* 2. 支持异步发布
|
||||
* 3. 支持结构化日志输出
|
||||
*
|
||||
* @author lzh
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DefaultBusinessLogPublisher implements BusinessLogPublisher {
|
||||
|
||||
// TODO: 注入实际的日志存储服务(如 MongoDB、Elasticsearch 等)
|
||||
// @Resource
|
||||
// private BusinessLogRepository businessLogRepository;
|
||||
|
||||
@Override
|
||||
public void publish(BusinessLogContext context) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 输出结构化日志
|
||||
log.info("[BusinessLog] type={}, scope={}, description={}, targetId={}, targetType={}, success={}",
|
||||
context.getType(),
|
||||
context.getScope(),
|
||||
context.getDescription(),
|
||||
context.getTargetId(),
|
||||
context.getTargetType(),
|
||||
context.getSuccess());
|
||||
|
||||
// TODO: 持久化到日志存储
|
||||
// businessLogRepository.save(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async("ops-task-executor")
|
||||
public void publishAsync(BusinessLogContext context) {
|
||||
publish(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishSuccess(BusinessLogContext context) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
context.setSuccess(true);
|
||||
publish(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishFailure(BusinessLogContext context, String errorMessage) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
context.setSuccess(false);
|
||||
context.setErrorMessage(errorMessage);
|
||||
publish(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publishError(BusinessLogContext context, Throwable throwable) {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
context.setSuccess(false);
|
||||
context.setErrorMessage(throwable != null ? throwable.getMessage() : "Unknown error");
|
||||
publish(context);
|
||||
|
||||
// 同时输出异常堆栈
|
||||
log.error("[BusinessLog] Error occurred", throwable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user