win120a opened a new pull request, #10292:
URL: https://github.com/apache/dubbo/pull/10292
## What is the purpose of the change
中文:
为 #10223 提供一种思路。
其提供一个继承于 Logger 接口的 ErrorTypeAwareLogger 接口。这个接口在记录日志时支持传入 ErrorType
对象,以确认异常的种类(可能原因)和对应的 FAQ 地址,从而能够实现在日志输出时同时附带输出对应的官网 FAQ 说明链接的功能。同时其与 Logger
接口独立,确保了向后兼容性。
English Version:
This proposal provides a solution of #10223.
It provides a interface called ErrorTypeAwareLogger, which extends Logger
interface. This interface supports receiving an ErrorType instance that
contains error cause and corresponding FAQ URL address. With that, the logger
will also outputs a URL to instructions. It's backward-compatible since it's a
seperate interface.
## Brief changelog
中文:
- 新增了一个 ErrorType,用于代表一种(类)异常,内有异常的可能原因和异常排除文档的 URL 地址。
- 新增了一个 ErrorTypeAwareLogger 接口,用于代表支持传递 ErrorType 的日志 API。并新增了对应的 Fail-safe
实现。
- 修改了工厂方法,使得它可以返回一个 ErrorTypeAwareLogger 对象。
- 新增了它们对应的测试。
English Version:
- Created a new enum called ErrorType that represents a kind of error. It
contains error cause and the corresponding address of solution document.
- ErrorTypeAwareLogger, a logger interface that receives an ErrorType. The
fail-safe implementation is also added.
- Changed the factory method of Logger. So that it can returns an instance
of ErrorTypeAwareLogger.
- Add some tests related to them.
## Verifying this change
调用测试方法 / Invoke testing method below:
`org.apache.dubbo.common.logger.support.FailsafeErrorTypeAwareLoggerTest#testInstructionShownOrNot`
代码如下 / Code is here:
```java
@Test
public void testInstructionShownOrNot() {
LoggerFactory.setLoggerAdapter(FrameworkModel.defaultModel(), "jdk");
ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(FailsafeErrorTypeAwareLoggerTest.class);
logger.error(ErrorType.REGISTRY_CENTER_OFFLINE, "error", new
Exception("error"));
}
```
运行可以看到输出了如下消息 / After runs, the console window prints out these message:
```
7月 09, 2022 6:05:10 下午 org.apache.dubbo.common.logger.jdk.JdkLogger error
严重: [DUBBO] error, dubbo version: , current host: (omitted). This may be
caused by registry center offline, go to http://dubbo.apache.org/ to find
instructions.
java.lang.Exception: error
....
```
<!-- Follow this checklist to help us incorporate your contribution quickly
and easily: -->
## Checklist
- [x] Make sure there is a
[GitHub_issue](https://github.com/apache/dubbo/issues) field for the change
(usually before you start working on it). Trivial changes like typos do not
require a GitHub issue. Your pull request should address just this issue,
without pulling in other changes - one PR resolves one issue.
- [ ] Each commit in the pull request should have a meaningful subject line
and body.
- [ ] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [ ] Check if is necessary to patch to Dubbo 3 if you are work on Dubbo 2.7
- [X] Write necessary unit-test to verify your logic correction, more mock a
little better when cross module dependency exist. If the new feature or
significant change is committed, please remember to add sample in [dubbo
samples](https://github.com/apache/dubbo-samples) project.
- [ ] Add some description to
[dubbo-website](https://github.com/apache/dubbo-website) project if you are
requesting to add a feature.
- [ ] GitHub Actions works fine on your own branch.
- [ ] If this contribution is large, please follow the [Software Donation
Guide](https://github.com/apache/dubbo/wiki/Software-donation-guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]