潘志宝
2024-11-21 70079bd0772207e88414176f5ca9edb3dd4bd236
提交 | 用户 | 时间
e7c126 1 package com.iailab.framework.apilog.core.service;
H 2
3 import com.iailab.module.infra.api.logger.ApiAccessLogApi;
4 import com.iailab.module.infra.api.logger.dto.ApiAccessLogCreateReqDTO;
5 import lombok.RequiredArgsConstructor;
325d2f 6 import lombok.extern.slf4j.Slf4j;
e7c126 7 import org.springframework.scheduling.annotation.Async;
H 8
9 /**
10  * API 访问日志 Framework Service 实现类
11  *
12  * 基于 {@link ApiAccessLogApi} 服务,记录访问日志
13  *
14  * @author iailab
15  */
16 @RequiredArgsConstructor
325d2f 17 @Slf4j
e7c126 18 public class ApiAccessLogFrameworkServiceImpl implements ApiAccessLogFrameworkService {
H 19
20     private final ApiAccessLogApi apiAccessLogApi;
21
22     @Override
23     @Async
24     public void createApiAccessLog(ApiAccessLogCreateReqDTO reqDTO) {
325d2f 25         try {
H 26             apiAccessLogApi.createApiAccessLog(reqDTO);
27         } catch (Throwable ex) {
28             // 由于 @Async 异步调用,这里打印下日志,更容易跟进
29             log.error("[createApiAccessLog][url({}) log({}) 发生异常]", reqDTO.getRequestUrl(), reqDTO, ex);
30         }
e7c126 31     }
H 32
33 }