Commit 99442ec05c29b8839dbf796628bad7f72b2b99da
1 parent
77193102
fix:ApiErrorLogServiceImpl 在微服务场景下,记录日志存在的循环调用的问题
Showing
1 changed file
with
10 additions
and
5 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/logger/ApiErrorLogServiceImpl.java
| ... | ... | @@ -40,11 +40,16 @@ public class ApiErrorLogServiceImpl implements ApiErrorLogService { |
| 40 | 40 | ApiErrorLogDO apiErrorLog = BeanUtils.toBean(createDTO, ApiErrorLogDO.class) |
| 41 | 41 | .setProcessStatus(ApiErrorLogProcessStatusEnum.INIT.getStatus()); |
| 42 | 42 | apiErrorLog.setRequestParams(StrUtils.maxLength(apiErrorLog.getRequestParams(), REQUEST_PARAMS_MAX_LENGTH)); |
| 43 | - if (TenantContextHolder.getTenantId() != null) { | |
| 44 | - apiErrorLogMapper.insert(apiErrorLog); | |
| 45 | - } else { | |
| 46 | - // 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败! | |
| 47 | - TenantUtils.executeIgnore(() -> apiErrorLogMapper.insert(apiErrorLog)); | |
| 43 | + try { | |
| 44 | + if (TenantContextHolder.getTenantId() != null) { | |
| 45 | + apiErrorLogMapper.insert(apiErrorLog); | |
| 46 | + } else { | |
| 47 | + // 极端情况下,上下文中没有租户时,此时忽略租户上下文,避免插入失败! | |
| 48 | + TenantUtils.executeIgnore(() -> apiErrorLogMapper.insert(apiErrorLog)); | |
| 49 | + } | |
| 50 | + } catch (Exception ex) { | |
| 51 | + // 兜底处理,目前只有 yudao-cloud 会发生:https://gitee.com/yudaocode/yudao-cloud-mini/issues/IC1O0A | |
| 52 | + log.error("[createApiErrorLog][记录时({}) 发生异常]", createDTO, ex); | |
| 48 | 53 | } |
| 49 | 54 | } |
| 50 | 55 | ... | ... |