Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Adds feature of displaying FAQ link in logger output. #10292

Merged
merged 10 commits into from
Jul 10, 2022

Conversation

win120a
Copy link
Contributor

@win120a win120a commented Jul 9, 2022

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.
  • To ensure flexibility, per project's request, remove the enumeration and add parameters into logger interface.
  • 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 return 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:

@Test
public void testInstructionShownOrNot() {
    LoggerFactory.setLoggerAdapter(FrameworkModel.defaultModel(), "jdk");

    ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(FailsafeErrorTypeAwareLoggerTest.class);

    logger.error("1-1", "Registry center", "May be it's offline.",
        "error message", new Exception("error"));
}

运行可以看到输出了如下消息 / After runs, the console window prints out these message:

7月 10, 2022 4:37:26 下午 org.apache.dubbo.common.logger.jdk.JdkLogger error
严重:  [DUBBO] error message, dubbo version: , current host: (...), error code: 1-1. This may be caused by Registry center, go to https://dubbo.apache.org/faq/1-1 to find instructions. May be it's offline.
java.lang.Exception: error
....

Checklist

  • Make sure there is a GitHub_issue 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
  • 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 project.
  • Add some description to 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.

@AlbumenJ AlbumenJ changed the base branch from 3.0 to 3.1 July 10, 2022 07:52
@AlbumenJ AlbumenJ changed the title [Feature] Adds feature of displaying FAQ link in logger output. / 初步添加在日志中输出 FAQ 链接的功能 #10223 [Feature] Adds feature of displaying FAQ link in logger output. Jul 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jul 10, 2022

Codecov Report

Merging #10292 (0b60bf5) into 3.1 (7d3fb63) will decrease coverage by 0.17%.
The diff coverage is 72.97%.

❗ Current head 0b60bf5 differs from pull request most recent head 531c83a. Consider uploading reports for the commit 531c83a to get more accurate results

@@             Coverage Diff              @@
##                3.1   #10292      +/-   ##
============================================
- Coverage     65.73%   65.56%   -0.18%     
+ Complexity      319      297      -22     
============================================
  Files          1233     1236       +3     
  Lines         53730    53904     +174     
  Branches       8111     8123      +12     
============================================
+ Hits          35322    35344      +22     
- Misses        14577    14709     +132     
- Partials       3831     3851      +20     
Impacted Files Coverage Δ
...pache/dubbo/registry/support/AbstractRegistry.java 74.91% <ø> (+0.69%) ⬆️
...dubbo/remoting/zookeeper/ZookeeperTransporter.java 83.33% <0.00%> (-5.56%) ⬇️
...n/logger/support/FailsafeErrorTypeAwareLogger.java 62.12% <62.12%> (ø)
...ava/org/apache/dubbo/rpc/model/FrameworkModel.java 91.44% <66.66%> (ø)
...pache/dubbo/registry/support/FailbackRegistry.java 63.59% <75.00%> (ø)
...he/dubbo/registry/zookeeper/ZookeeperRegistry.java 65.31% <80.00%> (ø)
...java/org/apache/dubbo/common/logger/ErrorType.java 100.00% <100.00%> (ø)
.../org/apache/dubbo/common/logger/LoggerFactory.java 39.70% <100.00%> (+2.78%) ⬆️
...he/dubbo/common/logger/support/FailsafeLogger.java 53.17% <100.00%> (+0.37%) ⬆️
...apache/dubbo/registry/retry/AbstractRetryTask.java 50.00% <100.00%> (ø)
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d3fb63...531c83a. Read the comment docs.

@win120a win120a requested a review from AlbumenJ July 10, 2022 08:43
@win120a win120a force-pushed the error_type_aware_logger branch from 27e61c9 to 4731fc1 Compare July 10, 2022 09:22
@AlbumenJ AlbumenJ merged commit 6095d71 into apache:3.1 Jul 10, 2022
@AlbumenJ AlbumenJ added this to the 3.1.0 milestone Aug 16, 2022
@win120a win120a deleted the error_type_aware_logger branch March 27, 2023 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants