diff --git a/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java b/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java index a30810f..5847499 100644 --- a/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java +++ b/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java @@ -40,6 +40,9 @@ public class ThreadPoolConfig { executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); + executor.setThreadNamePrefix("async-pool-"); + executor.setWaitForTasksToCompleteOnShutdown(true); + executor.setAwaitTerminationSeconds(30); // 线程池对拒绝任务(无线程可用)的处理策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return executor; diff --git a/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java b/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java index b88ae78..0c96a78 100644 --- a/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java +++ b/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; @@ -25,6 +26,9 @@ public class RequestLoggingInterceptor implements HandlerInterceptor { private static final String START_TIME_ATTRIBUTE = "startTime"; public static final String BUSINESS_RESULT_ATTRIBUTE = "requestLoggingBusinessResult"; + @Value("${logging.business-error-as-warn:false}") + private boolean businessErrorAsWarn; + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @@ -208,8 +212,13 @@ public class RequestLoggingInterceptor implements HandlerInterceptor { long duration, BusinessResult businessResult) { String template = "Request completed: {} {} - {} {} ({}ms) businessCode={} success={} message={}"; if (isBusinessError(businessResult)) { - log.error(template, method, uri, status, statusText, duration, - businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + if (businessErrorAsWarn) { + log.warn(template, method, uri, status, statusText, duration, + businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + } else { + log.error(template, method, uri, status, statusText, duration, + businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + } } else if (isBusinessWarn(businessResult)) { log.warn(template, method, uri, status, statusText, duration, businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage());