update - 增加动态记录 api log 的参数

This commit is contained in:
wangli 2024-04-19 11:31:45 +08:00
parent 5ef673fda0
commit 83d438a6cf

View File

@ -7,6 +7,8 @@ import com.google.common.base.Strings;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC; import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -26,8 +28,11 @@ import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
*/ */
@Component @Component
@Slf4j @Slf4j
@RefreshScope
public class ApiLogListener implements ApplicationListener<ApiLogEvent> { public class ApiLogListener implements ApplicationListener<ApiLogEvent> {
@Value("${workflow.apiLog.enable: false}")
private Boolean enable;
@Resource @Resource
private ExtAxApiLogService apiLogService; private ExtAxApiLogService apiLogService;
private static final List<String> EXCLUDE_URLS = new ArrayList<>(); private static final List<String> EXCLUDE_URLS = new ArrayList<>();
@ -40,7 +45,7 @@ public class ApiLogListener implements ApplicationListener<ApiLogEvent> {
@Override @Override
@Async @Async
public void onApplicationEvent(ApiLogEvent event) { public void onApplicationEvent(ApiLogEvent event) {
if (EXCLUDE_URLS.contains(event.getApiUrl())) { if (!enable || EXCLUDE_URLS.contains(event.getApiUrl())) {
return; return;
} }
rebuildTraceId(event); rebuildTraceId(event);