提交 ca1d764e 编写于 作者: K kimi

DUBBO-438 ExceptionFilter在服务器端打印日志时显示客户端的IP

上级 83b69b79
...@@ -27,6 +27,7 @@ import com.alibaba.dubbo.rpc.Filter; ...@@ -27,6 +27,7 @@ import com.alibaba.dubbo.rpc.Filter;
import com.alibaba.dubbo.rpc.Invocation; import com.alibaba.dubbo.rpc.Invocation;
import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.Invoker;
import com.alibaba.dubbo.rpc.Result; import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
import com.alibaba.dubbo.rpc.RpcException; import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcResult; import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.service.GenericService; import com.alibaba.dubbo.rpc.service.GenericService;
...@@ -72,7 +73,7 @@ public class ExceptionFilter implements Filter { ...@@ -72,7 +73,7 @@ public class ExceptionFilter implements Filter {
return result; return result;
} }
// 未在方法签名上定义的异常,在服务器端打印ERROR日志 // 未在方法签名上定义的异常,在服务器端打印ERROR日志
logger.error("Got unchecked and undeclared exception. service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception); logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + exception.getClass().getName() + ": " + exception.getMessage(), exception);
// 异常类和接口类在同一jar包里,直接抛出 // 异常类和接口类在同一jar包里,直接抛出
String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface()); String serviceFile = ReflectUtils.getCodeBase(invoker.getInterface());
String exceptionFile = ReflectUtils.getCodeBase(exception.getClass()); String exceptionFile = ReflectUtils.getCodeBase(exception.getClass());
...@@ -97,7 +98,7 @@ public class ExceptionFilter implements Filter { ...@@ -97,7 +98,7 @@ public class ExceptionFilter implements Filter {
} }
return result; return result;
} catch (RuntimeException e) { } catch (RuntimeException e) {
logger.error("Got unchecked and undeclared exception. service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e); logger.error("Got unchecked and undeclared exception which called by " + RpcContext.getContext().getRemoteHost() + ". service: " + invoker.getInterface().getName() + ", method: " + invocation.getMethodName() + ", exception: " + e.getClass().getName() + ": " + e.getMessage(), e);
throw e; throw e;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册