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

[ISSUE #6906] Fix create NacosNamingService instance failure #6907

Closed
wants to merge 4 commits into from

Conversation

yuhaowin
Copy link
Contributor

@yuhaowin yuhaowin commented Sep 17, 2021

Please do not create a Pull Request without creating an issue first.

What is the purpose of the change

Fix when dependency high version logback, low version slf4j, create NacosNamingService instance failure。

For #6906

Brief changelog

change NacosLogging determine logger type method

Verifying this change

when dependency logback,but effective logger is another logger implementation,for instance log4j,able to create NacosLoggin instance.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a Github issue filed 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.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. 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.
  • 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 integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@CLAassistant
Copy link

CLAassistant commented Sep 17, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@KomachiSion
Copy link
Collaborator

Have you test the old version slf4j and logback can run well after your modified?

@yuhaowin
Copy link
Contributor Author

Have you test the old version slf4j and logback can run well after your modified?

I don't konw how to test this with Junit, but i install it in my repository after modified, it's work for old version slf4j and logback.

@@ -33,15 +33,12 @@

@Test
public void testLoadConfiguration() {
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
Configuration contextConfiguration = loggerContext.getConfiguration();
Assert.assertEquals(0, contextConfiguration.getLoggers().size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this logic?

because nacos-client dependency log4j and logback, but actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory], and the binding is determined by the JVM, so when run mvn clean install -DskipITs , the method NacosLogging.getInstance().loadConfiguration() is executed in com.alibaba.nacos.client.utils.LogUtils, and
contextConfiguration.getLoggers().size() is more than one.

why it is work well before i modifed this issue? because effective logger is log4j, but determined logback, executed LogbackNacosLogging().loadConfiguration(), contextConfiguration.getLoggers().size() still zero.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But CI can pass, which means the old implementation is correct.

If can't remove this logic can't pass this case after your changes. We need more consider your changes whether has problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But CI can pass, which means the old implementation is correct.

If can't remove this logic can't pass this case after your changes. We need more consider your changes whether has problem.

ok, thanks for your reply, But I still think just executed Class.forName("ch.qos.logback.classic.Logger") whthout exception, determined current logger instance is logback, is not particularly appropriate.

Copy link
Collaborator

@KomachiSion KomachiSion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the PR provide a better one way to handle this problem.

But the problem is how to define the test case.

@yuhaowin
Copy link
Contributor Author

yuhaowin commented Dec 4, 2021

[nacos-client] moudle current used org.apache.logging.slf4j.Log4jLogger implement, mvn test first load Log4J2NacosLogging then execute unit test.

Xnip2021-12-04_18-41-56

@KomachiSion
Copy link
Collaborator

CLA not sign for a long time.

@KomachiSion KomachiSion closed this May 9, 2022
@yuhaowin yuhaowin deleted the develop-issue#6906 branch February 6, 2023 01:58
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.

4 participants