Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[SPARK-48592][INFRA] Add scala style check for logging message inline…
… variables
  • Loading branch information
asl3 committed Jun 12, 2024
commit 47710c92bc5077ddb9a91db7b088b901e07bce88
8 changes: 8 additions & 0 deletions scalastyle-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ This file is divided into 3 sections:
<customMessage><![CDATA[MDC should be used in string interpolation log"..." instead of s"..."]]></customMessage>
</check>

<check customId="logInlineVariable" level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters><parameter name="regex">log(?:Info|Warning|Error)\(s".*(\$|\+\s*[^\s"]).*"\)</parameter></parameters>
Copy link
Member

Choose a reason for hiding this comment

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

we need to detect the ".format(..)` as well.
Also, need to exclude the testing code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar rules also need to be added to dev/checkstyle.xml to check Java code

Copy link
Contributor

@LuciferYang LuciferYang Jun 13, 2024

Choose a reason for hiding this comment

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

Also, need to exclude the testing code.

This might be difficult, as for scalastyle-maven-plugin, there is currently no mechanism similar to Java checkstyle's SuppressionFilter that can ignore certain rules in specific files or code blocks. The rule ignoring of scalastyle is global and cannot be targeted at specific files or code blocks. After defining the check rule, we may only be able to skip the relevant checks in a way similar to the following:

// scalastyle:off logInlineVariable
logInfo(s"....")
// scalastyle:on logInlineVariable

<customMessage>
Logging message should use log"..." instead of s"..." and variables should be wrapped in `MDC`s.
Refer to Structured Logging Framework guidelines in the file `internal/Logging.scala`.
</customMessage>
</check>

<check customId="hadoopconfiguration" level="error" class="org.scalastyle.file.RegexChecker" enabled="true">
<parameters><parameter name="regex">spark(.sqlContext)?.sparkContext.hadoopConfiguration</parameter></parameters>
<customMessage><![CDATA[
Expand Down