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

[SPARK-48214][INFRA] Ban import org.slf4j.Logger & org.slf4j.LoggerFactory #46502

Closed
wants to merge 5 commits into from

Conversation

panbingkun
Copy link
Contributor

@panbingkun panbingkun commented May 9, 2024

What changes were proposed in this pull request?

The pr aims to ban import org.slf4j.Logger & org.slf4j.LoggerFactory.

Why are the changes needed?

After the migration of structured logs on the java side is completed, we need to ban import org.slf4j.Logger & org.slf4j.LoggerFactory in the code to avoid the log format that is not written as required in the future new java code.

Does this PR introduce any user-facing change?

Yes, only for spark developers.

How was this patch tested?

  • Manually test.
  • Pass GA.

Was this patch authored or co-authored using generative AI tooling?

No.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

It seems to reveal that we have too many exceptions for this new rule though.

@panbingkun
Copy link
Contributor Author

  • According to @gengliangwang's suggestion, we did not migrate the test code in the structured log, so we need to exclude them, eg:
image
  • Other exclusion is: common/kvstore/src/main/java/org/apache/spark/util/kvstore/LevelDBIterator.java
image A.the module `common/kvstore`, because it does not rely on 'utils' when compiling, if we want to `migrate` it, we need to add a `dependency` on 'utils' in `pom.xml` https://github.com/apache/spark/blob/master/common/kvstore/pom.xml#L38-L66

B.And only one place in this module use 'slf4j', as shown below:


And we found that this error level log does not use variables
So at present, it seems that migration is not necessary. Of course, migration is also possible.

@dongjoon-hyun
Copy link
Member

cc @gengliangwang

@gengliangwang
Copy link
Member

I am +1 for the idea.
However, I wonder if there will be suggestions about why the two imports are not allowed and how to fix the style error.
If that's not feasible with IllegalImport, shall we use RegexpSinglelineJava and show proper suggestions instead?

@panbingkun
Copy link
Contributor Author

I am +1 for the idea. However, I wonder if there will be suggestions about why the two imports are not allowed and how to fix the style error. If that's not feasible with IllegalImport, shall we use RegexpSinglelineJava and show proper suggestions instead?

Well, it makes sense,
the illegalimport does not provide a friendly prompt information interface,
let me to update it later.

@LuciferYang
Copy link
Contributor

LuciferYang commented May 10, 2024

Or how about having these modules depend on the common/utils module? common/utils doesn't seem to be a heavyweight module, in this way, the existing cases can be fixed.

@panbingkun
Copy link
Contributor Author

sh dev/lint-java

Using `mvn` from path: /Users/panbingkun/Developer/infra/maven/maven/bin/mvn
-e Checkstyle checks failed at following occurrences:
[ERROR] src/main/java/org/apache/spark/util/kvstore/LevelDBIterator.java:[33] (regexp) RegexpSinglelineJava: Please use org.apache.spark.internal.(Logger|LoggerFactory) instead.
[ERROR] src/main/java/org/apache/spark/util/kvstore/LevelDBIterator.java:[34] (regexp) RegexpSinglelineJava: Please use org.apache.spark.internal.(Logger|LoggerFactory) instead

@panbingkun panbingkun marked this pull request as ready for review May 14, 2024 08:08
@panbingkun
Copy link
Contributor Author

Or how about having these modules depend on the common/utils module? common/utils doesn't seem to be a heavyweight module, in this way, the existing cases can be fixed.

Done.

@panbingkun
Copy link
Contributor Author

Ready for it, @gengliangwang @dongjoon-hyun @LuciferYang

@gengliangwang
Copy link
Member

@panbingkun let's hold on this until we have a conclusion in #46600

@panbingkun
Copy link
Contributor Author

@panbingkun let's hold on this until we have a conclusion in #46600

@gengliangwang
After #46600, the pr has updated.

public class SparkLoggerFactory {

public static SparkLogger getLogger(String name) {
org.slf4j.Logger slf4jLogger = org.slf4j.LoggerFactory.getLogger(name);
return new SparkLogger(slf4jLogger);
return new SparkLogger(LoggerFactory.getLogger(name));
Copy link
Member

Choose a reason for hiding this comment

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

yeah this looks better

@gengliangwang
Copy link
Member

Thanks, merging to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants