update dubbo 请求日志增加日志等级
parent
c28d9c208e
commit
337ef9761b
|
|
@ -45,6 +45,8 @@ dubbo:
|
||||||
custom:
|
custom:
|
||||||
# 全局请求log
|
# 全局请求log
|
||||||
request-log: true
|
request-log: true
|
||||||
|
# info 基础信息 param 参数信息 full 全部
|
||||||
|
log-level: info
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
main:
|
main:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.ruoyi.common.dubbo.enumd;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求日志泛型
|
||||||
|
*
|
||||||
|
* @author Lion Li
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum RequestLogEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* info 基础信息 param 参数信息 full 全部
|
||||||
|
*/
|
||||||
|
INFO, PARAM, FULL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ package com.ruoyi.common.dubbo.filter;
|
||||||
|
|
||||||
import com.ruoyi.common.core.utils.JsonUtils;
|
import com.ruoyi.common.core.utils.JsonUtils;
|
||||||
import com.ruoyi.common.core.utils.SpringUtils;
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import com.ruoyi.common.dubbo.enumd.RequestLogEnum;
|
||||||
import com.ruoyi.common.dubbo.properties.DubboCustomProperties;
|
import com.ruoyi.common.dubbo.properties.DubboCustomProperties;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.dubbo.common.constants.CommonConstants;
|
import org.apache.dubbo.common.constants.CommonConstants;
|
||||||
|
|
@ -30,7 +31,11 @@ public class DubboRequestFilter implements Filter {
|
||||||
client = CommonConstants.CONSUMER;
|
client = CommonConstants.CONSUMER;
|
||||||
}
|
}
|
||||||
String baselog = "Client[" + client + "],InterfaceName=[" + invocation.getInvoker().getInterface().getSimpleName() + "],MethodName=[" + invocation.getMethodName() + "]";
|
String baselog = "Client[" + client + "],InterfaceName=[" + invocation.getInvoker().getInterface().getSimpleName() + "],MethodName=[" + invocation.getMethodName() + "]";
|
||||||
log.info("DUBBO - 服务调用: {},Parameter={}", baselog, invocation.getArguments());
|
if (properties.getLogLevel() == RequestLogEnum.INFO) {
|
||||||
|
log.info("DUBBO - 服务调用: {}", baselog);
|
||||||
|
} else {
|
||||||
|
log.info("DUBBO - 服务调用: {},Parameter={}", baselog, invocation.getArguments());
|
||||||
|
}
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
// 执行接口调用逻辑
|
// 执行接口调用逻辑
|
||||||
|
|
@ -41,7 +46,11 @@ public class DubboRequestFilter implements Filter {
|
||||||
if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
|
if (result.hasException() && invoker.getInterface().equals(GenericService.class)) {
|
||||||
log.error("DUBBO - 服务异常: {},Exception={}", baselog, result.getException());
|
log.error("DUBBO - 服务异常: {},Exception={}", baselog, result.getException());
|
||||||
} else {
|
} else {
|
||||||
log.info("DUBBO - 服务响应: {},SpendTime=[{}ms],Response={}", baselog, elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
|
if (properties.getLogLevel() == RequestLogEnum.INFO) {
|
||||||
|
log.info("DUBBO - 服务响应: {},SpendTime=[{}ms]", baselog, elapsed);
|
||||||
|
} else if (properties.getLogLevel() == RequestLogEnum.FULL) {
|
||||||
|
log.info("DUBBO - 服务响应: {},SpendTime=[{}ms],Response={}", baselog, elapsed, JsonUtils.toJsonString(new Object[]{result.getValue()}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ruoyi.common.dubbo.properties;
|
package com.ruoyi.common.dubbo.properties;
|
||||||
|
|
||||||
|
import com.ruoyi.common.dubbo.enumd.RequestLogEnum;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
|
@ -17,4 +18,7 @@ import org.springframework.stereotype.Component;
|
||||||
public class DubboCustomProperties {
|
public class DubboCustomProperties {
|
||||||
|
|
||||||
private Boolean requestLog;
|
private Boolean requestLog;
|
||||||
|
|
||||||
|
private RequestLogEnum logLevel;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue